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 meta key in question and conditionally add the meta box. There is a generic add_meta_boxes
hook that always runs, but other add_meta_boxes_CPTSLUG
hooks that are limited to particular post types. My example applies only to pages.
If your content is a resource intensive as you say, I’d look into transients.
Related Posts:
- How to change default position of WP meta boxes?
- Custom Taxonomy as checkbox or dropdown
- Why won’t my metabox data save?
- echo value from ‘select’ field type into page template using cmb2?
- WP_List_Table Inside Metabox Not Working on Submit
- Add metabox with media uploader in a custom post type [duplicate]
- wp_generate_attachment_metadata gives me an empty array
- Best way to arrange custom post types by Attributes -> Order metabox value?
- Removing Edit Permalink/View “Custom Post Type” areas
- Unable to save custom taxonomy terms in a custom-built metabox
- Order custom posts by a date metabox
- How to sort CPT by custom meta value (date), and return posts month by month
- Custom post type’s slug gets wrong when adding a custom meta box
- update a post meta from a single table cell TablePress
- How to create a repeatable / reusable divs in the metabox?
- How to add meta boxes(repeater fields) from WordPress back end?
- Displaying Meta Box Image
- How to customize the Categories meta box to allow only one category?
- wp is not defined error using wp.media to create a custom image uploader
- Displaying custom posts only if custom meta box’s date is not expired
- Displaying Metabox value (custom post type taxonomy)
- Hide Meta Boxes for Non-Admins
- Add TinyMCE to CPT metaboxes in 3.1?
- WordPress nl2br is not converting newline to html line break when saving metabox value
- advanced search forms with 3 input text and that the main problem 3 input text
- Create custom PAGE with register_post_type
- Using My-Meta-Box-Class plugin, how is ‘Date’ value stored?
- What’s the difference between same wp functions get_posts(); functions in different form?
- Keep display metadata value on backend – Custom Metabox
- Populate dropdown from one custom post type inside another custom post type
- Custom Post Type with Templates using Meta Boxes?
- Why is my select meta data not saving?
- What is the best way to correlate one-to-many content-type relationships?
- Visual editor issue by having multiple tiny mce editors in a CPT
- A better way to add a meta box to custom post types
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Grouping metadatas into one
- Anon function and add_meta_box
- Create Connection Between two post types
- Listing custom terms in custom post meta
- Can custom fields be added without a meta box?
- Meta Box on Custom Post Type not saving
- Moving meta boxes in admin
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- custom post type metaboxes not saving
- Custom post type, have only my meta boxes
- Display Repeatable Meta Box Content
- Can I restrict category availability?
- Saving Meta Data within Custom Post Type
- Using custom post type as taxonomy
- Values from meta-box not on $_POST
- Metabox multiple custom post select -> display selected items?
- Get id from metabox dropdown
- Custom posttype content metabox
- Reusable metabox backend and frontend
- Filter posts of custom post type by meta key in (List All Section)
- How can I output WPAlchemy repeating fields meta values in my page template?
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- Meta box data not saving
- saving dropdown menu data on custom post type
- Questions regarding add_meta_box()
- Related posts meta_query CPT
- Meta box with front-end styling
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Cannot Save MetaBox Data in Custom Post Type
- Custom post type meta box empty after save
- How to add a class to meta boxes (to customize them in CSS)?
- Problem On Retrieving Post Meta Data on Custom Column [closed]
- Custom MetaBox : Food Menu Item Available Dates
- how to compare different timestamps in wp-query for events custom post types?
- Metaboxes inside Tab
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Create post meta box that links another post
- Show a custom post title in another custom post type in Meta box
- How to avoid duplicate posts queried from custom meta?
- Modify Publish Metabox location on CPT
- PHP Warning with Custom Fields
- Custom taxonomy with custom post type archive page
- Simple Data picker meta box
- Wrong post ID in meta box callback
- Metabox messes up permalink
- How to shows CPT which has specific meta key?
- Render the metabox input values as HTML
- wp_dropdown_pages doesn’t allow me to select more than one custom post type
- Delete custom post type metadata without deleting the post in admin area
- Metabox is not saving
- How to check if meta box value is false for all posts then do something based on that
- Custom metabox fields not saving when limited to a certain CPT
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- Display a post count from a custom metabox selection
- Select custom post by meta value
- Make meta box appear if the previous if not empty?
- Adapting plugin for custom post type?
- Custom post type – permalink
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- How to query custom post then display sections by meta value
- Custom meta box includes
- Post AND page parameter for WP function
- Display div based on Group metabox selection [closed]
- How to consume external API from WordPress post editor and display the response data in the custom field?