Reputation: 265
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.
Update -
Adding the following code to my functions.php file allows the member-resources CPT to show in Category and Tags pages respectively, but now in the wordpress backend under the "Pages" tab and all other content tabs such as posts etc it seems to have overrided my pages and posts and is showing just the member-resources posts.
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;
}
Upvotes: 0
Views: 1481
Reputation: 216
your code looks correct. but you are including the CPT member-resources in too many of wordpress's queries. the is_main_query means "the loop" i think.
so you need to restrict this to just running when on a tag archive page.
the following code is from the wordpress site
add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' );
function foo_modify_query_exclude_category( $query ) {
if ( ! is_admin() && is_main_query() && ! $query->get( 'cat' ) )
$query->set( 'cat', '-5' );
}
You need to do a similar thing but determine if you are in a "tags" page.
Upvotes: 1