Display metabox conditionally

Of course… function generic_cb($post) { echo ‘This is a test of the emergency callback system.’; } add_action( ‘add_meta_boxes_page’, ‘conditional_meta_box’ ); function conditional_meta_box($post) { $meta = get_post_meta($post->ID,’meta_key’,true); if (‘abc’ === $meta) { add_meta_box( ’emcb’, ‘CB Test’, ‘generic_cb’, ‘page’, ‘normal’, ‘high’ ); } } The add_meta_boxes* hooks pass the $post variable, so use it to check the … Read more

Save checkboxes of a metabox with a foreach loop (invalid argument)

My advise would be to extract the query portion of your code: function get_brands() { $loop_brands = array(); wp_nonce_field( plugin_basename( __FILE__ ), ‘brands-nonce-field’ ); $args = array( ‘post_type’ => ‘page’, ‘post_parent’ => 7, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); $query_brands = new WP_Query($args); return $query_brands; } Then use it like this: function brands_save_meta_box( $post_id … Read more

Undefined index: at_nonce in custom post metabox

These are your problem lines: if ( $_POST && !wp_verify_nonce($_POST[‘at_nonce’], __FILE__) ) { return; } You check to see that $_POST is set, but you don’t check $_POST[‘at_nonce’]. If $_POST is set but that key is not then you will get a Notice. It is a simple fix: if ( isset($_POST[‘at_nonce’]) && !wp_verify_nonce($_POST[‘at_nonce’], __FILE__) ) … Read more

Why is `add_meta_box` not working?

I can see 2 problems with your code. You seem to want that meta box to appear on product pages, but you actually add it to the post type and not the product post type. The other problem is the hook you attach your function to. Try this: add_action( ‘add_meta_boxes_{post_type}’, ‘abc_load_post’ ); Substitute {post_type} with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)