There is a reference in the KB to storing the post id of a created post. (https://formidableforms.com/knowledgebase/frm_after_create_entry/#kb-save-the-id-of-created-post-in-a-field).
add_action('frm_after_create_entry', 'save_post_id', 60, 2);
function save_post_id( $entry_id, $form_id ) {
if ( $form_id == 341 ) {// Replace 341 with the ID of your form
$entry = FrmEntry::getOne( $entry_id );
if ( ! $entry->post_id ) {
return;
}
FrmEntryMeta::add_entry_meta( $entry_id, 1290, "", $entry->post_id); // Replace 1290 with the ID of the field where the postID should be saved
}
}
I am using this snippet exactly as written (with the correct form and field ids, of course), but post_id is not getting stored.
So I added an else clause to print_r the $entry to the error_log, and behold, the post_id is not even there.
[06-Jan-2025 15:05:07 UTC] stdClass Object
(
[id] => 558
[item_key] => vywa1
[name] => Leo Walker's 2025 hike for mental health
[description] => Array
(
[browser] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
[referrer] => https://ihike.org/register/?event-id=8
)
[ip] => 99.72.151.148
[form_id] => 4
[post_id] => 0
[user_id] => 1
[parent_item_id] => 0
[is_draft] => 0
[updated_by] => 1
[created_at] => 2025-01-06 15:05:07
[updated_at] => 2025-01-06 15:05:07
[form_name] => Event Registration
[form_key] => hfmh-event-registration
[metas] => Array
(
[60] => 8
etc for the rest of the metas....
Any ideas why the post_id is not being passed? The post is in fact being created properly.
As a follow-up, it is not a timing issue. I pulled the $entry for that $entry_id much later to examine it. post_id is still set to 0.
The code you're using is completely unnecessary if you're using the create post add-on. I justed tested the create post add-on in my development environment. The add-on creates the post_id and stores it in the entry without any issues. You have to be doing something wrong for the post_id not to be written to the frm_items table. Post_id is a standard field in frm_items.
When you want to display a post_id, Formidable provides the [post_id] shortcode.
Provide a screen print of you have the add-on configured, please.
Please login or Register to submit your answer