Take the 2-minute tour ×

Edit 2:

So having worked a lot on this I have come along way and have a solution that indeed allows me to filter taxonomies by page template, however it isn't very DRY or very flexible. Ideally I would like to make this even more flexible so that I can use it to link several templates and taxonomies.

The problem I ran into was that if I define the taxonomies array outside of the function it doesn't work even though I am passing it through as an argument. Im having one of those days where I have looked at this code for so long that I cant see the wood for the trees. Can anyone possibly help by giving some tips on refactoring this to make it more DRY.


function create_taxonomy($name,$type = 'page') {
    // create a new taxonomy
        strtolower( str_replace(' ','-', $name ) ),
            'label'     => __( $name ),
            'sort'      => true,
            'rewrite'   => array( 'slug' => strtolower( str_replace(' ','-', $name ) ) )

    //return strtolower(str_replace(' ','-', $name));


function case_study_taxonomy($template,$taxonomies){

    $current_template = get_post_meta($_GET['post'], '_wp_page_template', true);

    if ($current_template == $template){

        $taxonomies = array(

            create_taxonomy('Project Type'),
            create_taxonomy('System Finishes'),
            create_taxonomy('System Installer'),
            create_taxonomy('Partnering Contractor'),

        foreach($taxonomies as $taxonomy){

            add_action( 'admin_menu', $taxonomy );




share|improve this question
Are you only using the page heirarchy for generating the menu or does it serve other purposes? –  sanchothefat Nov 11 '11 at 17:45
add comment

1 Answer

I'm not entirely sure I understand your explanation of how things are set up, or if it's the best way to go about what you're trying to do, but to answer your specific question-

the selected template for a page is stored in post meta under the key _wp_page_template, you can check this key to see if your case study template is selected, otherwise use remove_meta_box to hide the taxonomy for all other pages.

share|improve this answer
Thanks you have pointed me in the right direction to answering my question with _wp_page_template –  roikles Nov 14 '11 at 13:49
add comment

Your Answer


