151 posts
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+4 more
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
  • Has been part of the Envato Community for over 3 years
  • Located in Canada
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
waywicked says

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

http://www.farinspace.com/page-specific-wordpress-meta-box/

and one step back:

http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/
66 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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.

by
by
by
by
by
by