Custom Fields
Re-Envisioned
Support General How can I update the post instead of Insert

This topic contains 3 replies, has 2 voices, and was last updated by  Anh Tran 6 months, 1 week ago.

  • Creator
    Topic
  • #13662

    calpaq
    Participant

    Hi Support,
    I have a requirement of saving meta data for CPT, the challenge is save data to the existing post if the same post title is already there and do not create a different post. so can you guide me that which hooks will trap these events and how to corealate wp hooks with metabox. eagerly waiting for your reply.

    Thanks & Regards,
    Calpaq

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #13681

    Anh Tran
    Keymaster

    Hi Calpaq, how do you save posts? I mean do you run a code to save posts or use Meta Box plugins?

    If you need to hook after Meta Box save post data, you can just use ‘rwmb_after_save_post’ hook, or save_post (with priority > 10). And then use update_post_meta to update meta data to an existing post of your choice.

    #13686

    calpaq
    Participant

    Hi Tran,
    Thanks for replying,
    This is all relaated with wordpress admin
    Let me tell you that I am not using any custom code to save posts and use meta box plugins. In my case I am using custom post type, so I have registered post type and by default its menu is added to wp admin so from there adding/updating/deleting posts. WordPress doesn’t validate for post title and it can add same title with different Id. What I want is to validate post title ( i.e. check if post exists and if found retrieve that post and update that instead of creating new post with again same title ). I am using some metabox fields for this post type and now I want to check before insert that if any post exist. So actually I do not want create/insert any new post (if exist ), retrieve the ID and save these meta fields to that existing post, Can you help me in saving these fields with existing post when its already there.
    Thanks & Regards

    #13706

    Anh Tran
    Keymaster

    I got it. I think the hard part in this situation is detect if there’s any existing post with the same title. I’m afraid I don’t have any that code available.

    Once you get that post (with post ID), you can use update_post_meta function to manually update fields.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.