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

Slack Signup
Newsletter Optin
Help Desk

Get created post id via a hook

Labels

This Discussion is public

Notifications

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.

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

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.

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
}
}

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.