Support » Plugin: Meta Box » Meta Box fields not up to date inside save_post action

  • Resolved jonnyhocks


    Hi guys,

    Just looking to add a small checkbox meta box which allows pages to automatically be added to a menu when the post/page is saved if it’s checked.

    The problem I’m running into is that when I get the meta inside the action, it’s the value BEFORE the save/update button was hit in WordPress. I’ve tested this out with the title and content etc and these all provide me with the correct data which was saved on the hitting of the button.

    Any help would be great, here is the code I’m using just to test it works:

    function auto_add_page_to_menu( $post_id ) {
    	// If this is just a revision, don't do anything
    	if ( wp_is_post_revision( $post_id ) )
    	$post_title = get_the_title( $post_id );
    	$post_url = get_permalink( $post_id );
    	$subject = 'A post has been updated';
    	$menu = get_post_meta($post_id, 'cff_add-to-menu', true);
    	if ($menu == 1) {
    		$added_to_menu = 'This page was added to menu';
    	} else {
    		$added_to_menu = 'This page is not to be added to the menu';
    	$message = "A post has been updated on your website:\n\n";
    	$message .= $added_to_menu . ": " . $post_url;
    	// Send email to admin.
    	wp_mail( '', $subject, $message );
    add_action( 'save_post', 'auto_add_page_to_menu' );

    NOTE: I am using the default WP method for getting the post meta here, but I get the same result if I use the rwmb_meta methods.

    Many thanks in advance!

Viewing 1 replies (of 1 total)
  • Found a way around it by accessing the value via $_REQUEST as demonstrated in the save_post documentation in the Codex.

Viewing 1 replies (of 1 total)
  • The topic ‘Meta Box fields not up to date inside save_post action’ is closed to new replies.