• rootsdigger05

    (@rootsdigger05)


    I am using WP Recipe Maker on my local machine with WP Studio. When I edit a recipe, I want WP Recipe Maker to automatically force an update to the parent post. I already have implemented code to show the last-edited post on the home page. I just need WP Recipe Maker to update the related post when editing and saving recipes.

    Please help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Brecht

    (@brechtvds)

    Hi there,

    I would have to recommend hooking into the save_post WordPress hook. You can then check if the post being saved has the wprm_recipe post type to then get the parent post of that recipe. Something like this should work:

    function wprm_update_parent_post_on_save( $post_id, $post ) {
    if ( 'wprm_recipe' === $post->post_type ) {
    $parent_post_id = get_post_meta( $post_id, 'wprm_parent_post_id', true );

    if ( $parent_post_id ) {
    wp_update_post( array(
    'ID' => $parent_post_id,
    ) );
    }
    }
    }
    add_action( 'save_post', 'wprm_update_parent_post_on_save', 10, 2 );

    Take note that I have not tested this exact code.

    Kind regards,
    Brecht

    Thread Starter rootsdigger05

    (@rootsdigger05)

    Brecht,

    Thank you for the code, however, it didn’t work. What is expected is that the parent post is edited and saved and then that post should be the first post (at top) on the home page. The code to show that post as first on the home page is already there. It seems that your code did not make the edit/save of the parent post as intended. But thanks for looking at it.

    Plugin Author Brecht

    (@brechtvds)

    I just tested that code and it does trigger an update of the parent post on my test site.

    You might need to update the post_date in wp_update_post, to have it show up at the top.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.