Tet banner

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

  • Creator
  • #13662

    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,

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

    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.


    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

    Anh Tran

    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.