151 posts
  • Microlancer Beta Tester
  • Most Wanted Bounty Winner
  • Referred between 100 and 199 users
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
  • United Kingdom
  • Bought between 1 and 9 items
RoyalTemplates says

Hi, I have run into a problem which Im not sure is possible with standard wordpress and no extra php. Basically I have a page template for “Hosting Plans” page. This displays a number of custom post types in a table (Plans).

What I would like to be able to do is to add a meta box with a list of “Plans” custom post types for the user to select. Its possible to add the meta box to all pages but I want it to only show if it is a page using the template “Hosting Plans”. Is this even possible?

1 post
  • Bought between 50 and 99 items
  • Canada
  • Exclusive Author
  • Has been a member for 3-4 years
waywicked says

Well this is 4 months later and may not help iStudios per se, for anyone else looking check these 2 great links:


and one step back:

6 posts
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • Has been a member for 2-3 years
  • India
  • Referred between 1 and 9 users
geekslabs says
If your custom page template filename is foobar.php, you can use get_post_meta():
global $post;
if ( 'foobar.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
    // The current page has the foobar template assigned
    // do something
Personally, I like calling this inside my add_meta_boxes_page callback, and wrapping it around the add_meta_box() call itself.
function wpse82477_add_meta_boxes_page() {
    global $post;
    if ( 'foobar.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
        add_meta_box( $args );
add_action( 'add_meta_boxes_page', 'wpse82477_add_meta_boxes_page' );

You’ll just need to instruct users to save the page after assigning the template, so that the meta box appears.