WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post Status and Post Meta Data (4 posts)

  1. TwoThirdsWater
    Member
    Posted 4 years ago #

    I'm working on a post-expires plugin, adapted from the atropos plugin.

    I've noticed that when the posts status is updated (from draft to published or visa-versa), the meta data I have saved against the post is lost (or loses its connection to the post). This is first time I've used meta-data at all (I'm usually a custom field kind guy) and don't know enough about how the meta relationships are formed. Please could someone advise me how to maintain the connection when the post status changes.

    Thank you!

    p.s. For those interested, the primary change I am making to atropos is to set expired posts status to "draft' rather than deleting the post.

  2. Rahul Sonar
    Member
    Posted 4 years ago #

    http://codex.wordpress.org/Post_Meta_Data_Section

    Post meta data are nothing but some information related to the post..., so it does not change even if you change the post status(at least it should not)..

    For saving additional informtion, you should always use custom fields. Changing the post status does not change the relation between a post and custom fields..

    Use this function to update the existing post:

    wp_insert_post

  3. TwoThirdsWater
    Member
    Posted 4 years ago #

    Thanks Rahul.

    I've made a bit of progress, reading the link you sent me I adapted the code further to use the functions:
    update_post_meta()
    add_post_meta()
    and
    delete_post_meta()

    This has partly solved the problem in that if I change the status of the post via the main post edit screen. The meta data is maintained, but if I do it via the quick-edit on the post list then the meta data is lost!

    I imagined that the code called would be the same for both of these processes, but clearly something different is going on!

  4. TwoThirdsWater
    Member
    Posted 4 years ago #

    Ah... solved my own problem.

    It seems the issue was the logic within the plugin when the post was saved. On the post edit screen the meta value was in place. On the quick edit, the post meta values were not there so the value was deleted by the plugin. I've put in a control now that stops this issue.

    Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.