• I have added a simple metabox with a checkbox that corresponds to a meta field.
    I have verified with xdebug that after posting, the metabox callback is called and returns the updated html, but for some reason it doesn’t update in the editor.

    function cabtv_add_post_options()
    {
    	// Add our meta box for the "post" post type (default)
    	if ( current_user_can("send_notifications") ) {
    		$post_types = ["post", "go_live"];
    		foreach ($post_types  as $post_type) {
    			add_meta_box(
    				'cabtv_notif_on_post',
    				'Notifications',
    				'cabtv_notif_on_post_html_view',
    				$post_type,
    				'side',
    				'high'
    			);
    		}
    	}
    }
    add_action('admin_init', 'cabtv_add_post_options');
    
    function cabtv_notif_on_post_html_view($post)
    {
    	//wp_nonce_field( 'cabtv_notif_metabox', 'cabtv_notif_metabox' );
    	$checked = cabtv_should_post_send_notification($post);
    	
    	if ( get_post_meta( $post->ID, 'cabtv_notifications_sent', true ) == "1" ) { ?>
    		<div style='padding:10px;'><span style='color:red; font-weight:bold;'>Notifications have already been sent for this post.</span></div>
    	<?php } ?>
    
    	<input type="hidden" name="cabtv_meta_box_present" value="true"></input>
    	<input type="checkbox" name="cabtv_send_notification" value="true" <?php if ($checked) echo 'checked'; ?>></input>
    	<label>
    	<?php echo esc_attr('Send notification on '.($post->post_status === 'publish' ? 'update' : 'publish') ); ?>
    	</label>
    <?php
    }

    Any ideas?

    • This topic was modified 4 years, 9 months ago by hedgehog90.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Try changing

    <input type="checkbox" name="cabtv_send_notification" value="true" <?php if ($checked) echo 'checked'; ?>></input>

    to this

    <input type="checkbox" name="cabtv_send_notification" value="true" <?php if ($checked):?>checked<?php endif; ?>; ?>></input>

    Thread Starter hedgehog90

    (@hedgehog90)

    It’s not a syntax error.
    I’ve just checked with another plugin that adds a meta box to the editor and it isn’t updating after posting either, but if I check the Network tab in Chrome Dev Tools I can see the the new page, with updated metabox values downloading as a resource.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘metabox html not updating after publish’ is closed to new replies.