1

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.

2
  • 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
    Commented Jan 23, 2013 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
    Commented Jan 23, 2013 at 13:16

1 Answer 1

3

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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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