Meta boxes not showing on custom post type. Blank page?

To add a meta box to multiple post types, one add_meta_box per post type is needed. In this example, instead of duplicating the same code, a foreach is used. More post types can be added to the array and the meta box will be added in all of them: add_action( ‘add_meta_boxes’, ‘add_custom_box_wpse_94701’ ); function add_custom_box_wpse_94701() … Read more

header specific meta box result detect url

global $post; $header_meta = get_post_meta($post->ID, ‘page-header-meta’, true); if( isset( $header_meta ) ) { echo ‘<h1>’ . $header_meta . ‘</h1>’; } else { echo ‘<h1>Knowledgebase</h1>’; } What this portion of code does is it checks the ‘page-header-meta’ value according to the page being displayed. IF your parent page has the metavalue set then the header will … Read more

How to set default screen options?

You are referring to the metaboxes on the admin post screen right? For that you don’t need a plugin, just drop the following into your functions.php file. // add_action(‘user_register’, ‘set_user_metaboxes’); add_action(‘admin_init’, ‘set_user_metaboxes’); function set_user_metaboxes($user_id=NULL) { // These are the metakeys we will need to update $meta_key[‘order’] = ‘meta-box-order_post’; $meta_key[‘hidden’] = ‘metaboxhidden_post’; // So this can … Read more

Meta Box Value not saving / populating?

Variables do not expand inside single quotes, so this– selected( $selected, ‘$post_type->name’— is literally checking for a string that looks like ‘$post_type->name’. If you are saving the option names, it should work if you just remove the quotes (though I did not run your code to test that). Your might be able to exclude what … Read more

Adding meta boxes to custom post type

Let’s say your post type is named product. You register your metabox with … add_action( ‘add_meta_boxes_product’, ‘register_product_metabox’ ); function register_product_metabox() { // register the metabox } You get the post id in your callback per post object now: function metabox_callback( $post ) { $field = get_post_meta( $post->ID ); } This happens because WordPress calls the … Read more