WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Compatibility with post revisions

[Resolved] Compatibility with post revisions

  • Josh Levinson

    @joshlevinson

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Josh Levinson

    @joshlevinson

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

    Moderator bcworkz

    @bcworkz

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Compatibility with post revisions’ is closed to new replies.
Skip to toolbar