WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Compatibility with post revisions (3 posts)

  1. Josh Levinson
    Member
    Posted 1 year ago #

    Hi all.

    I have a custom post type 'location'. I am creating a system so that when a new location is created, a post of type 'office' is created with some post meta corresponding to the location post's data.

    Here is my code: http://pastebin.com/D27KLFM2
    (I am fairly new at PHP...so if you find some faults beside those mentioned in this post feel free to inform me).

    The code currently updates the post meta of the new office 'wpcf-location-list' with the post ID of a revision of the new location, instead of the final location post's ID. The desired result of this function is to have the post meta of the newly created office be set to the final ID of the new location.

    I assigned the $locID to get the $post_id in case the post ID was being changed somewhere before that line, before I realized it was a revision that was causing the problem.

    What can I do to make my function compatible with WP's revision system?
    Again, the desired result of this function is to have the post meta of the newly created office be set to the final ID of the new location.

    Thanks ahead for any input!

  2. Josh Levinson
    Member
    Posted 1 year ago #

    I can confirm that the problem is with revisions, as when I disable revisions (in wp-config), the code functions as desired.

  3. bcworkz
    Member
    Posted 1 year ago #

    You need to hook a more specific action to avoid the "noise" of all the different reasons 'save_post' fires. You want to use the action '{$old_status}_to_{$new_status}'. To capture new publish actions only, I believe the variables resolve to 'draft_to_publish', but if that is wrong, experiment with 'transition_post_status' action to determine the correct values.

Topic Closed

This topic has been closed to new replies.

About this Topic