cjerrells (@cjerrells)

Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • @cjerrells

    Participant

    + thanks @tharsheblows for posting the patches above! 🙂

    @cjerrells

    Participant

    Is there a reason the fixes in the patches above haven’t been integrated into trunk?

    This has been driving our users crazy and I’m surprised to find such an old thread here with an apparent solution. I made the changes and it seems fixed. Is there a hidden downside or complication that’s prevented it from becoming part of the standard codebase?

    @cjerrells

    Participant

    @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!

    @cjerrells

    Participant

    Thanks @atmojones, that worked for me!

    @cjerrells

    Participant

    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.

Viewing 5 replies - 1 through 5 (of 5 total)