Metabox not saving values

This is my working code // Add meta box function frontpage_meta_boxes( $post ){ global $post; if(!empty($post)) $page_template = get_post_meta( $post->ID, ‘_wp_page_template’, true ); { $pageTemplate = get_post_meta($post->ID, ‘_wp_page_template’, true); if($pageTemplate == ‘page-home.php’ ) { add_meta_box( ‘frontpage_meta_box’, __( ‘Features’ ), ‘frontpage_meta_box’, ‘page’, ‘advanced’, ‘high’ ); } } } add_action( ‘add_meta_boxes_page’, ‘frontpage_meta_boxes’ ); // builds our meta … Read more

Saving multiple fields (dropdown and text) in custom metabox

It looks like the variable you’re using to set the selected item is not defined in that scope. In your constructor: public function __construct() { if ( is_admin() ) { add_action( ‘load-post.php’, array( $this, ‘init_metabox’ ) ); add_action( ‘load-post-new.php’, array( $this, ‘init_metabox’ ) ); } $this->dropdown_args = [ ‘show_option_none’ => ‘- select a page -‘, … Read more

get_post_meta giving errors while creating a metabox

The error there clearly says that there’s an undefined variable (post) in your metabox callback function. So you need to define $post in your function head: // The $post variable is passed by WordPress. function diwp_post_metabox_callback( $post ) And you should also do the same to diwp_save_custom_metabox() function (which is hooked to save_post): // Here, … Read more