Post Data missing content and taxonomy in submissions
-
I have a form with post data writing to a CPT, which is working fine. But in the form submissions, not all of the post data is showing up. Title and Custom Fields are there, but the Content and a custom taxonomy are missing. These do get written to the created posts as expected, just not to the submissions (and email notifications that include the Post Data field).
These submissions need to be approved by an admin so we need the full data in the submissions and/or emails. There are extra fields in those which are not saved to the post (only needed for vetting the info) so viewing the post isn’t the solution.
Thank you!
-
Hello @tnightingale !
I’m sorry to hear you’ve experienced this issue!
I tried to replicate this on my site, but wasn’t able to – maybe there’s some specific setting you have that I don’t know of. Can you export the form so we can take a closer look and see what is happening? If so, please follow these steps:
How to export: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export
After exporting, please share the code using a service such as https://pastebin.com (free)
Please always make sure to use such service to share the code and don’t post the code here directly as it will most likely be unusable.
Kind regards,
PawelThank you – here is the form code (creates a single post – I also have one that creates up to 5 posts that does the same thing).
I switched to using the excerpt instead of the content, and the excerpt does show up in submissions and emails (and it’s a plain text input box on the form, which I want). But the custom taxonomy (“country”) is still missing. And that’s one of the most important parts of the submission.Also is there any way to make the post data fields look better in the submissions/emails? Remove the label “Postdata” for one. It uses the default post field names instead of the labels set in the form. Listing the custom fields is redundant as they’re also in the form (and it uses their field names – not a good UI for the reviewer).
Thank you!
Thank you for response!
I just imported your form to my own test site and since the “country” taxonomy didn’t exist there, I just create another custom one and added it to form. I could replicate the issue: the post got created correctly and selected taxonomy term was assigned to it as expected.
But neither submission data nor the notification got that taxonomy/taxonomy term included.
I did some more testing and it seem to be a bug that applies to custom taxonomies only (generic categories and tags for posts are correctly included in submissions).
I’m afraid I don’t have “out of the box” solution for this yet. I’ve reported it to our Forminator Team as a bug so they’ll check it and work on a fix to be included with one of upcoming releases.
As for the notification content, a workaround here is to use individual fields in notifications content instead of “all_fields” and/or “all_non_empty_fields” tags. With individual field tags the tag will output only field value (except for fields like Post Data where it also will output additional labels but will at least skip the “postdata” word itself).
Kind regards,
AdamThanks for the reply, good to know it’ll be fixed in an upcoming release.
In the meantime, for the email notifications is there a way to use a custom_value field to retrieve the postdata Title separately? and maybe also the custom taxonomy term? Something like {postdata-1.title} ?
Thanks for the reply, good to know it’ll be fixed in an upcoming release.
I’m sorry if I caused confusion but just to make it clear: it will be fixed with one of upcoming releases but I cannot promise it will be the nearest one at this point. I understand that this is important and I can assure you that our developers we’ll do their best to get it addressed as soon as possible but Forminator has the longest list of planned features and improvements out of all our plugins and while fixing bugs is obviously a priority there still is some development cycle and plans that need to be followd.
But I can confirm that our Forminator team is already aware of this and will work on a fix to get it delivered as soon as possible.
In the meantime, for the email notifications is there a way to use a custom_value field to retrieve the postdata Title separately? and maybe also the custom taxonomy term? Something like {postdata-1.title} ?
It’s not possible out of the box but I suppose it may be doable with a bit of custom code. I’ve asked our developers to look into it and see if we could provide such code for you. Again, I’d rather not make promises as this requires custom code but they’ll check it and if it’s only doable, we’ll let you know here and share code.
Kind regards,
AdamHello there @tnightingale
Our devs prepared a custom snippet for you that should do the trick. Please install the following as a new MU plugin file as mentioned here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
<?php add_filter( 'forminator_replace_form_data', 'wpmudev_post_data_macros', 10, 3 ); function wpmudev_post_data_macros( $content, $data, $original_content ){ if( $data['form_id'] != 2508 ){ //Please change the form ID return $content; } if( !isset( $data['postdata-1'] ) ){ return $content; } if( strpos( $content, '{post-excerpt}' ) !== false ){ if( isset( $data['postdata-1']['post-excerpt'] ) ){ $content = str_replace( '{post-excerpt}', $data['postdata-1']['post-excerpt'], $content ); } } if( strpos( $content, '{post-title}' ) !== false ){ if( isset( $data['postdata-1']['post-title'] ) ){ $content = str_replace( '{post-title}', $data['postdata-1']['post-title'], $content ); } } if( strpos( $content, '{post-term}' ) !== false ){ if( isset( $data['postdata-1']['country'] ) ){ $term_name = get_term( $data['postdata-1']['country'] )->name; $content = str_replace( '{post-term}', $term_name, $content ); } } return $content; }
You will have to change the form ID from 2508 to your form’s ID, it can be found in the corresponding shortcode.
After implementing the snippet you can use the following macros:
{post-excerpt} for excerpt,
{post-title} for title and
{post-term} for country data.Please first test in a staging/dev environment or have at least a full backup if deployed to a live/production site.
Thank you,
DimitrisWow, you guys are fast – thank you so much! I will try this and let you know. The site is still a dev site so I can test it out there.
Quick question: I have 2 other forms that submit up to 5 posts like this in one form.
Would I check for the other form IDs like this (using the real form id’s of course):if( $data['form_id'] != 2508 && $data['form_id'] != 2509 && $data['form_id'] != 2510 ){
Then could I add copies of the four if statements except with postdata-2, postdata-3, etc and use {post-excerpt-2}, {post-title-2} and {post-term-2} etc for the macros?
I’ll test it on the single version first though.
Tx.Actually the excerpt doesn’t need adding, it already shows up in submissions. It was the content that was missing (and title, and custom tax term).
Working perfectly for email notifications – thanks! (as tested on single postdata form)
FYI the stored submissions are still missing the custom taxonomy term. They do show the post title and excerpt, as they did by default.
So the exact fix needed is: add post title, post content, and custom tax term to email notifications with postdata fields; and add post content and custom tax term to stored submissions with postdata fields.
I hope you are doing well.
Our developers updated the code, you can try this version:
add_filter( 'forminator_replace_form_data', 'wpmudev_post_data_macros', 10, 3 ); function wpmudev_post_data_macros( $content, $data, $original_content ){ if( $data['form_id'] != 2508 ){ //Please change the form ID return $content; } if( !isset( $data['postdata-1'] ) ){ return $content; } if( strpos( $content, '{post-content}' ) !== false ){ if( isset( $data['postdata-1']['post-content'] ) ){ $content = str_replace( '{post-content}', $data['postdata-1']['post-content'], $content ); } } if( strpos( $content, '{post-excerpt}' ) !== false ){ if( isset( $data['postdata-1']['post-excerpt'] ) ){ $content = str_replace( '{post-excerpt}', $data['postdata-1']['post-excerpt'], $content ); } } if( strpos( $content, '{post-title}' ) !== false ){ if( isset( $data['postdata-1']['post-title'] ) ){ $content = str_replace( '{post-title}', $data['postdata-1']['post-title'], $content ); } } if( strpos( $content, '{post-term}' ) !== false ){ if( isset( $data['postdata-1']['country'] ) ){ $term_name = get_term( $data['postdata-1']['country'] )->name; $content = str_replace( '{post-term}', $term_name, $content ); } } return $content; } add_filter( 'forminator_entry_meta_value_to_string', 'wpmudev_show_post_country_entry', 10, 5 ); function wpmudev_show_post_country_entry( $string_value, $field_type, $meta_value, $allow_html, $truncate ){ if( $field_type == 'postdata' ){ if( ! empty( $meta_value['postdata'] ) ){ if( !empty( $meta_value['value']['country'] ) ){ $post_country = $meta_value['value']['country']; $the_countries = ''; $countegories = 0; $single_label = esc_html__( 'Country', 'forminator' ); if ( is_array( $post_country ) ) { foreach( $post_country as $country ) { $countries[] = get_the_category_by_ID( $country ); } $countegories = count( $countries ); $the_countries = implode( ', ', $countries ); } else { $the_countries = get_the_category_by_ID( $post_country ); } if ( $allow_html ) { $value = '<hr>'; if ( is_array( $post_country ) ) { $value .= '<b>' . esc_html( _n( 'Country', 'Countries', $countegories, 'forminator' ) ) . ':</b> '; } else { $value .= '<b>' . $single_label . ':</b> '; } $value .= $the_countries; } else { $value .= $single_label . ': '; $value .= $the_countries . ' | '; } $value .= '<hr>'; $string_value .= $value; } } } return $string_value; }
You can now use:
{post-content}
Similar to the previous solution, you need to update the ID to match your form.
The second function is to fetch the post country and display it under submissions/entries.
Best Regards
Patrick FreitasAmazing. Thank you so much, I’ll test this out today!
- The topic ‘Post Data missing content and taxonomy in submissions’ is closed to new replies.