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/
72 posts
  • Sells items exclusively on Envato Market
  • Has sold $1,000+ on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
+2 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by