Reply To: Creating a reply programmatically, it doesn't appear in the forums
@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!