Put code below to your functions.php
add_filter(‘pre_get_posts’, ‘query_post_type’);
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var(‘post_type’);
if($post_type)
$post_type = $post_type;
else
$post_type = array(‘post’,’cpt’); // replace cpt to your custom post type
$query->set(‘post_type’,$post_type);
return $query;
}
}
Related Posts:
- Custom post type archive 404’s with paginate_links
- Display Custom Post Type Fields
- Retrieving 3 latest post from each of 5 different custom post types
- how to group custom post type posts by custom taxonomy terms
- Using Query Posts With Multiple Post Types And A Taxonomy
- How to get the parent’s taxonomy?
- Combine tax_query and meta_query in WP_Query
- Query not returning CPT posts
- Unable to display multiple post types in same query (WPML WP_Query)
- Query for posts in 2 taxonomies
- Quickest way to get last or oldest post date – WP Query
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Calculating Bayesian average for custom post type
- Custom query shows custom post types in trash
- Multiple post type queries (with specific arguments for each)
- wpdb custom post_type problem
- Sorting multiple custom post types without a meta key/value pair by sort order
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Get latest 3 posts from multiple CPT in one query
- Polylang non-default language ignores tags in WP_Query
- Different Ways to Query Custom Post Types?
- pagination not working for category.php (custom post types in categories)
- How to display Related Posts based on number of taxonomy terms matched
- Proper way to display latest 5 posts grouped by post type?
- How to make WP_Query not to show irrelevant posts?
- Loop for custom post types filtered by a taxonomy
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Pagination not working on custom query on a page
- find custom post type post by searching its custom field with my string
- FacetWP paging custom wp_query
- Can’t change posts per page in WordPress Post Type Query
- postsperpage value not being applied
- Custom Post Type Query W/Category Dropdown
- Find Posts based on Child Post value
- Custom Post Type ‘Event’: Chronological list of recurring events from meta_values in array
- Sorting the Loop by Taxonomy Value
- Custom Query: Multiple CPTs and a taxonomy filter
- WP query_posts group by meta field related
- Custom wp-query display post only today
- custom post type and a “sticky” position taxonomy
- Use WP_query to match post types based on custom field values
- minimize wp_query call to database
- Query the title of the page to show posts with matching category in the loop
- Main site single-property.php design, as homepage of a multisite
- Imported Content Doesnt Show Up On Frontend
- Custom post order when using OR relation
- WordPress custom post type
- display news with pictures 3 small and one large (loop)
- Custom Query With Multiple Meta Key Value
- Custom post type blog pagination conflict
- Query Posts From Multiple Post Types
- send user to first page of results when reposting to page?
- How do I correctly query posts from a post ID?
- How to exclude certain portfolios from a loop
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- Display ACF object field data using Elementor Custom Query
- How do I query a custom post type with a custom taxonomy?
- Multiple orderby values in WP_Query
- Return all custom meta data for one custom post type
- How to display only top level posts in loop via WP_Query?
- Related posts by author pagination not working on the production site
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Loading post content in FancyBox
- Used with meta_query in query_posts works slowly
- Query for custom posts with a specific tag slug
- WP-Admin edit.php & post.php slowdown after import of 10k users
- WordPress Orderby Numeric Value Not Working
- How to add pagination to wp_query [duplicate]
- Show one item per category of a custom post type
- Storing posts from query and accessing later via AJAX call
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- Query Custom posts of same taxonomy as the post itself
- Show only one post on custom post type archive
- Category with post type pagination returns 404
- First custom field value (out of several) displayed twice after query
- WP_query – Filter by tax_query and meta_query using multiple select
- Create a list of recent Custom Post Types posts
- Empty search input does not return all posts
- How to sort a WP_Query by a custom field AND ALSO filter by a different custom field
- Get current user id
- Limit custom post type to the authors only on front-end!
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- Foreach result into WP_query
- Query custom post type and custom field by URL parameters
- Query posts based on user preferences
- Querying, storing, and using data from 2 separate custom post types
- How can I use WP_Query argument ‘Like %..%’?
- WordPress custom post type queries
- Custom Post ‘Post Per Page’ Crashing Page?
- Query child posts on parents single.php?
- Custom Post Query Combined with Conditional Tags
- Custom loop won’t work, can’t find problem
- Query by post type or category
- Get all custom_post_type posts + blog posts from one category in a single query
- Customising wordpress search and using $_GET[“s”]
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- show the most recent date of all posts to display on front end