I can only suggest that you create a new topic using your programme
Then I’d look at everything in the database in wp_posts & wp_postmeta that has that ID
Take a copy of all of this
Then hit the update in the backend and see what has changed
Thank you for the suggestion! This has helped me find the problem.
Gravity Forms lets you set custom fields on posts created, but not all of the core post properties. So it turns out that my approach was creating a new custom field called “post_parent” rather than actually setting the “post_parent” property of the post.
I’m not sure why re-saving the post in the backend solved this issue, but I’ve now set up a hook which monitors for new posts and if a particular custom field is set, then sets the “post_parent” property correctly, and my auto-generated replies are now showing up in the thread as expected. Great! Thanks again.
Great – glad you’re fixed, and thanks for posting what you did, this will help anyone looking at this thread !
cjerrels,
I have essentially wound up at the same point as you, except saving on the backend isn’t what put (in my case) the topic in the correct forum, but adding a reply to the topic did.
What is the hook you used to “monitor for new posts and if a particular custom field is set, then sets the “post_parent” property correctly?”
@jsteckler1,
I have no idea on how things were setup, but just to add my idea:
– On save_post, launch your own routine
– in your routine, if it’s a topic, set the post_parent to the forum ID (so _bbp_forum_id)
– in your routine, it it’s a reply, set the post_parent to the topic ID (so _bbp_topic_id)
@jsteckler1: We use GF to set a custom field called “_mu_autogenerated_post_to” and then our code looks like this:
/*
* Small fix for posting new introductions to the introductions thread
* Would be nice to use the GF hook but post_id not set with Custom Post Types addon -_-
*/
function set_post_parent($post_id)
{
if (get_post_meta($post_id,"_mu_autogenerated_post_to",true))
{
remove_action( 'save_post', 'set_post_parent',10); // Avoid infinite loop when wp_update_post calls save_post
$target_discussion = get_post_meta($post_id,"_mu_autogenerated_post_to",true);
error_log("Detected new _mu_autogenerated_post_to " . $target_discussion);
wp_update_post( array('ID' => $post_id,'post_parent'=>$target_discussion) );
error_log("Updated post parent.");
add_action( 'save_post', 'set_post_parent',10);
}
else
{
// error_log("Ignoring non-_mu_autogenerated_post_to post creation");
}
}
add_action( 'save_post', 'set_post_parent',10);
Hope that helps!
Hi @casiepa,
Thank you for jumping in!
Some additional details about my situation:
Upon submission of a specified Gravity Form, I am attempting to create a new topic under a specified forum (Forum ID: 31086).
While creating the new Topic was simple enough with the Custom Post add-on—which successfully created the Topic, including the body of the topic post, accordingly—the topic was being listed under “No Forum.” @cjerrells post got me closer, encouraging me to add another custom field named _bbp_forum_id with a default value of 31086 (the forum ID). After doing that, the assigned forum seemed to display correctly on the backend, but:
1) The breadcrumb would only display the forum after editing and resaving the post again
— It still will not, however, show on the front-end forum among the other forum topics
2) The topic would finally display correctly on the front-end among the other forum topics only after adding a reply to the topic post.
Here is a screenshot of my Gravity Form settings, as well as the code cjerrells kindly provided within my functions.php file. My ability to write php is still very elementary, and it seems a bit difficult to find a full list of bbPress actions and hooks, so I wasn’t sure exactly what needed to be altered to fit my needs.
I would be beyond appreciative if you could give it all a look and get back to me with any thoughts or ideas you may have.
Hi @casiepa,
I have failed in my attempt to set post_parent to _bbp_forum_id. Could you help me build on the code provided by @cjerrells perhaps? Though he was focused on replies, we were both experiencing the same issue on the front-end.
Or, alternatively, I am only using ONE forum. Is there any code I could use to force ALL topics created to be sent to a specified forum?