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.

I have many custom post types and they all take advantage of wordpress categories. I therefore have several parent categories for each custom post type. Is there a way to hide the other parent categories when editing a certain custom post type?

In this screenshot for example I'd only like "Download Categories" to show while I'm in my custom post type "downloads".

enter image description here

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Probably you're making a wrong use of taxonomies. Instead of using only the Categories taxonomy, you should create several Custom Taxonomies.

I mean Blog Categories, Download Categories, Team Departments, etc... should be different taxonomies, and you should assing each of these taxonomies to the custom post type(s) they're related to...

Check the function register_taxonomy() for further information.

This is a very simple example:

function register_download_category() {
    register_taxonomy(
        'downloadcategory',
        'downloads',
        array(
            'label' => 'Download Categories',
            'rewrite' => array( 'slug' => 'downloadcategory' ),
        )
     );
}
add_action( 'init', 'register_download_category' );

In order to make queries by custom taxonomies you have to use the WP_Query Taxonomy Parameters.

share|improve this answer
    
You are correct I should be using that. When I use 'category_name' in get_posts shall I replace this with 'tax_query' to be able to search for posts in a particular custom taxonomy? –  GreenGiant Mar 31 at 10:24
1  
@GreenGiant, yes exactly, you can use tax_query or I guess you can directly use 'downloadcategory' => 'payroll' for example. See the link I added at the end of the answer for further info... –  MikO Mar 31 at 10:33
    
Ah yer 'customtax' => 'catslug' works too, much cleaner than an array with tax_query. Thank you so much! –  GreenGiant Mar 31 at 10:40

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.