The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Get created post id via a hook
Is there a hook I can use to get the ID of a post created by a Formidable form. I'm looking to add post meta to the created post as soon as it's been added.
December 10, 2018 at 4:43 am
This is the only hook I'm aware of that links to the new post. You can try this: https://formidableforms.com/knowledgebase/frm_new_post/#kb-save-entry-id-in-custom-field
December 10, 2018 at 5:04 pm
Thanks, but unfortunately this only give access to the entry id (the form submission record) not the new post id.
I've add a had a look through the formidable code and can't see any way of getting the id of a created post. Seems a bit of an oversight, would be very useful hook to have.
December 11, 2018 at 6:27 am
When you create a post with Formidable, there is a link created to the original form entry. The link is the post id that is stored in the post_id field in the the wp_frm_items table. So here's some custom code I wrote for you this morning that will retrieve the post id and add it to the field of your choosing:
add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id) {
global $wpdb;
if ( $form_id == 2 ) {
$table_name = $wpdb->prefix . 'frm_items';
$post_id = $wpdb->get_var( "SELECT post_id FROM " . $table_name . " where id = " . $entry_id );
FrmEntryMeta::add_entry_meta( $entry_id, 131, "", $post_id); //change 131 to the ID of the field in which you want to store the post ID
}
}
December 11, 2018 at 5:15 pm
Thanks Victor, I didn't think to look at the entry in the database to see if the post id was there. I really appreciate your help with this :)
Discussion closed.