1

For my WordPress theme I have a custom portfolio post type and a portfolio page template to display them. What I want to do is add a meta box to the edit page area, but only when the page has the portfolio template.

Thanks.

2
function my_portfolio_meta_box_cb($post) {
     $template = get_post_meta($post->ID, '_wp_page_template', true);
     if ($template == 'portfolio.php') {
         add_meta_box(........);
     }
}

Hook this via the register_meta_box_cb arg when registering the post type or in your manually via add_meta_boxes-portfolio hook.

1
  • sorry for my english, how can we put this in a select option onchenge it meen that when qe choise the template the add_meta_box apear just in that moment. thanks h.
    – user5010
    Apr 30 '11 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy