Replies made with Gravity Forms invisible on front end
-
I am using Gravity Forms and their Advanced Post Creation Add-On to submit replies to topics in my forum.
I added a code snippet to add the post_parent to the reply using the gform after submission hook.
I checked in the database, and that is working properly.
The only problem is that the reply does not show up on the front end…until I update it, then it works properly.
Is there something I am missing in this process?
-
Given that’d a paid add-on, you should refer to them in the first instance.
I did refer to them and they said that I should find out what metadata was needed by BBPress, and make sure that was added when the form was submitted.
I researched the docs here and found that I needed to include _bbp_forum_id and _bbp_topic_id. So, the replies were being posted to the correct forum and topic, but they weren’t showing up on the front end of the forum. I read elsewhere in this forum that the post_parent had to be updated, so I did that using a code snippet.
But, the problem is that I am missing something for BBPress. Gravity Forms and the extension are working properly, but something is missing in BBPress until I update the topic from the back end.
ok, so your form submission adds things to the metadata – yes ? or no ?
just seeing if we need to update metadata or just run an update?
Do you have the ability in gravity forms to link to an action on form submission ?
Yes, my form submission adds things to the metadata.
When I open up All Replies in the admin panel, it shows that the reply is in the proper forum and topic. If I edit the reply from there, and hit update, everything shows properly in the forum. Before I update it, it does not show up on the front end.
Yes, I can link to an action on form submission.
Thanks for your help!
without a deep dive into your code and gravity, we’ll need to guess at answers.
I presume you are not running any caching software?
if not then you could tie a new reply to the action on submission.
so if you have data, then the new_reply_handler in \includes\replies\functions.php starting at line 125 might be what you need.
if you have $_POST data, then it might be as simple as
add_action( 'whatever_your_actions_hook_is', 'bbp_new_reply_handler', 10 );
It appears that the post_parent is no longer updating in the database for some reason. So, I am trying to fix that, and to run the bbp update programatically as well because that seems to fix it when I run it on replies in the admin panel. This is the code I am using, but it isn’t working.
This is what I have so far. Does anything look wrong to you?
add_action( 'gform_post_submission', 'set_post_content', 10, 2 ); function set_post_content( $entry, $form ) { //getting post $post = get_post( $entry['post_id'] ); //getting meta values $topicID = get_post_meta($post,'_bbp_topic_id',true); $forumID = get_post_meta($post,'_bbp_forum_id',true); $reply_data = array('post_parent'=>$topicID); $reply_meta = array('forum_id'=>$forumID, 'topic_id' => $topicID); bbp_update_reply($reply_data,$reply_meta); }
looks ok without testing – does it work ?
No, it is really weird. When I submit the form, it creates two database entries, a reply first and then a revision. The reply has a post_parent of 0, and the revision has a post_parent number that matches the post ID of the reply.
The post meta has the correct forum and topic.
If I go into the WP admin panel and find the reply, then hit update, the reply in the database changes, and gets the proper post_parent automatically, and the revision is unchanged.
ok, so exactly what in the database (post and post meta) changes when you update in wp_admin?
The only thing that changes that I can see is the post_parent gets updated to the correct topic id in the posts table.
However, I have tried to change that value using phpMyAdmin, and it didn’t make the reply show up in the forum front end.
ok, so check what changes in post and post meta for the topic itself?
There were no changes to the topic entry in post or postmeta after I updated a reply.
ok, I can only suggest that you have some caching software – otherwise I’m out of ideas
Revisions are totally a WordPress thing. It’s weird, but sounds accurate.
Using Gravity Forms to create new topics & replies will bypass the “freshness” hooks that bbPress expects to run normally. This means that the “branch” of topics & forums in the “tree” of that submission won’t get walked up to the root, to tell that whole branch what its most recent content is.
Once you post something yourself normally, the tree gets walked and everything looks OK.
The function that would normally be called is
bbp_update_topic()
. It includes all of the extra meta data that needs to be added – including a call tobbp_update_topic_walker()
that “walks” the branch in the tree.Lastly, it refreshes the
last_changed
cache key in thebbpress_posts
cache group. You could try busting that cache on your Gravity Forms submission (to see if that’s enough) but I have a feeling it won’t be, and you’ll need to find the best way to trigger the update.
- You must be logged in to reply to this topic.