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 a made a custom post type called "Member Resources" the posts under this CPT have a few taxonomies such as categories and tags.

Tags = "Diversity" Categories = "Guidance"

When I go to the following urls:

www.domain.com/tags/diversity

www.domain.com/tags/guidance

No posts appear.

Though I have set public => true on the CPT function.

Posts are displaying if you go to the Member Resources archive page though, so they are displaying, but not when you filter them by taxonomies.

Any help would be appreciated!

Thanks.

share|improve this question
    
Ok, so I found this little bit of code on the codex - add_action( 'pre_get_posts', 'add_my_custom_post_type' ); function add_my_custom_post_type( $query ) { if ($query->is_main_query()) $query->set( 'post_type', array( 'member-resources' ) ); return $query; } This works a charm, so it seems. But I'm baffled why, by default my custom post types are not being shown in tags and category pages? I have even registered them in the CPT. Could anyone explain why this is? –  rowefx Jan 23 '13 at 12:49
    
Further to this it now deletes my "Pages" and "Posts" content and shows only the member-resources posts in these areas? –  rowefx Jan 23 '13 at 13:16

1 Answer 1

up vote 1 down vote accepted

You were close with the code you posted in your comment. The issue is that you only tested for is_main_query, which will limit every query on your site to that single post type.

function wpa82763_custom_type_in_categories( $query ) {
    if ( $query->is_main_query()
    && ( $query->is_category() || $query->is_tag() ) ) {
        $query->set( 'post_type', array( 'post', 'resource' ) );
    }
}
add_action( 'pre_get_posts', 'wpa82763_custom_type_in_categories' );
share|improve this answer

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.