How to add a meta box for a particular page, say: for only About Us page.
How shall i do?
The current code adds the metaboxes for all pages:
function myplugin_add_custom_box() {
add_meta_box(
'myplugin_sectionid',
__( 'My Post Section Title', 'myplugin_textdomain' ),
'myplugin_inner_custom_box',
'post'
);
add_meta_box(
'myplugin_sectionid',
__( 'My Post Section Title', 'myplugin_textdomain' ),
'myplugin_inner_custom_box',
'page'
);
}
Here is a function that you can pass either a single post id or an array of ids. Call this function in your function that adds the meta boxes. If the id or ids don’t match the meta boxes will not display on that post or page.
Here’s another possibility: show or hide the Meta Box according to the page template or to the post category.
page-wpse-53486.php
is the template filename.form#adv-settings label[for='myplugin_sectionid-hide
is the meta box option inside the Screen options. We don’t want it to appear if the meta box is not available for the post/page.#in-category-6
is the checkbox for the category with ID 6.