• I don’t know why it’s so difficult to get and work with the post meta on post save. In the save_post filters, the post meta is not always available in the $_POST or $_REQUEST object, and the post meta from the database is not always updated by the time the hook is called.

    There is an updated_postmeta hook in the meta field update, but that is not an ideal place to hook into when attempting to catch save/update post actions.

    There is a wp_insert_post_data FILTER, but filters are used to modify data and return the modified data, actions are used to perform actions, so this too is not ideal.

    The $postarr object should really be sent along with the save/update post action hooks so that ALL of the sent data can be manipulated after save. At the very least, the post meta.

    I have never understood why I have to test a thousand different hacks just to get the post meta on save post to work with. And why when one works for some site, for some reason, it doesn’t work on others.

    There is always some workaround, but the save post action hook is really where this stuff should be handled and the meta fields should be readily accessible to this action. Both a before and after save. If you would like me to provide use cases, I can.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Justin Sternberg

    (@jtsternberg)

    You will need to hook into the save_post hook after CMB2 does. Something like:

    
    add_action( 'save_post', 'your_function_callback', 20, 2 );
    
    Thread Starter aryanduntley

    (@dunar21)

    The priority parameter. Still does not provide the post meta. But definitely something I overlook too often.

    @dunar21 I feel the same. I have been banging my head since yesterday but can’t get the updated post meta value in the save_post action. And like you said, that post meta value is not available in $_POST/$_REQUEST object. So I don’t know how to get it. This should’ve been so simple.

    WordPress docs says save_post “Fires once a post has been saved.” In this case, I should be able to get all updated post meta inside my function.

    • This reply was modified 3 years, 2 months ago by Sajjad Ali.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post Meta in Save Post Hook’ is closed to new replies.