Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks.

function create_taxonomy($name,$type = 'page') {
    // create a new taxonomy
    register_taxonomy(
        strtolower( str_replace(' ','-', $name ) ),
        $type,
        array(
            'label'     => __( $name ),
            'sort'      => true,
            'args'      => array( 'orderby' => 'term_order' ),
            '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('Client'),
            create_taxonomy('System Installer'),
            create_taxonomy('Architect'),
            create_taxonomy('Partnering Contractor'),
        );

        foreach($taxonomies as $taxonomy){

            add_action( 'admin_menu', $taxonomy );

        }

    }   

}

case_study_taxonomy('template-case-study.php',$taxonomies);
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.