Forums

[Learned Lesson] Plugin adding using meta on a post and revisions (1 post)

  1. moronicbajebus
    Member
    Posted 1 year ago #

    With 2.6, I ran into some issues with a plugin I am creating which saves its data with in the post meta. The problem is the revision system because my plugin is passed the revision ID (not the post ID) when the post is saved. Here is the code snippet I found to translate the revision ID to the post ID.

    // saving
    if ($the_post = wp_is_post_revision($post_id)){
       $post_id = $the_post;
    }
    add_post_meta($post_id, $key, $value, true) or update_post_meta($post_id, $key, $value);
    // retrieving
    if ($the_post = wp_is_post_revision($post_id)){
       $post_id = $the_post;
    }
    get_post_meta($post_id, $key, true);

    It would be great if this part of the API is updated to give control regarding the revisions.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by moronicbajebus
  • WordPress version: 2.6
  • This topic is not a support question