Support

Account

Home Forums General Issues update_post_meta not working with acf

Helping

update_post_meta not working with acf

  • Hi everybody!

    I’m trying to update a custom field “test” whenever a post type ‘review’ is being saved. Eventually I want to keep track of the total amount of reviews by putting the amount in a custom field.

    For this I’ve put following code in functions.php but can’t get it to work:

    add_action('save_post_reviews', 'publish_function');	
    
    function publish_function( $post_id )
    {
    	global $wpdb;
    	$update = "updated";
    	update_post_meta( $post_id, 'test', $update );
    }

    What am I doing wrong?

  • Hi @sanderjansma

    There are a few ideas in the above code which show what the isue could be:
    1. the action ‘save_post_reviews’ is run BEFORE the save_post so ACF is overriding your value. Have you placed any debug code in your function to stop the page loading and look at your DB to see if the code worked?
    2. Please use the update_field function instead of update_post_meta. This is ACF friendly.

    Basically, you will need to debug the issue to find out if the value is being saved, if the value is being overridden, etc.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘update_post_meta not working with acf’ is closed to new replies.