You can use pre_get_posts hook to modify the main query, or any WP_Query for that matter. For example like this,
add_action(
'pre_get_posts',
function($query) {
// target only public category main query
if (
is_admin() ||
! $query->is_main_query() ||
! is_category()
) {
return;
}
// include custom post type in the query
$query->set( 'post_type', array( 'post', 'story' ) );
}
);
Related Posts:
- List all custom post type posts from a given category?
- Show Post Count of a Category
- category_name not working in WP_Query
- How to change permalink structure for custom post type and it’s taxonomies?
- Get the first post term
- WP_Query by a category id and a custom post_type
- Exclude a category from WP_Query
- Creating “static” taxonomies to choose from, inside custom post type?
- How can I list all the categories under a Custom Post Type (taxonomy)?
- WP_Query ignores post_type in category view
- How to list all categories and tags in a page?
- category__in not working on custom post type
- How to sort list of custom posts to get view like a tree of posts under categories and their children’s categories?
- How can you make permalink work for custom post type and taxonomy?
- How to get a list of term names of the custom post type im currently on in single.php
- How to get the parent’s taxonomy?
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- List with categories, subcategories and posts of custom posttype
- New WP_query in template not working with CPT+category on some pages
- WP Query group/order by category name
- Custom post type taxonomy template
- WP_Query with custom post_type and cat retrieving unwanted posts with the custom posts
- Query Custom Post by Category
- Loop through categories and create tab for each
- get_categories for custom post type and filter by custom taxonomy (brand) and list child categories of a defined category
- Getting all custom posts with a certain category
- Category page only displaying the posts from a custom type
- Query Custom Post Types & category_name?
- CPT posts listed by category with custom rewrite URL, please help!
- Custom Post Types and Categories?
- How to create new category for custom post type?
- Fetch taxonomies by custom post type id array
- Pagination is not working on single-{slug}.php but works fine on page-{slug}.php
- How to get the post type from a category id?
- Pagination on category page with custom post types
- Why does querying on post_tags (which has been applied to custom post types) only return posts?
- Display all posts in main category and 1 subcategory
- showing custom post types of a certain category only
- Linking to the most recent post in a Custom Post Type
- Show category ID on custom post type
- Show custom post type filtered by category
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- Custom post taxonomies as tax_query terms?
- Several post types on WP Query by tag and taxonomy
- WP Query with categories only shows one post and ignores the category
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- WP the_posts() on single-cars.php get category link
- Categories and tags for custom post types
- Variable not working in WP_Query
- get_category_link() for custom post type does not include custom slug rewrite?
- Targeting categories in custom fields
- Invalid Taxonomy
- Need help deciding on a taxonomy
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Query all post and CPT from 2 specific taxonomies AND by ACF custom field
- Get Posts by Category, Tag , and CPT Taxonomy
- Get assigned post categories
- WP Query results showing posts outside of category ID
- Default Category Page not showing custom post type which has taxonomy category
- How to get Custom Post Type with Categories wise in WordPress using wp_query
- Running a custom query inside another cpt single and trying to grab a variable
- Custom Post Type with modified permalink structure results in 404
- Get posts by category name
- How to properly use Categories with Custom Post Types
- Query Custom Post Type by Taxonomy
- Page that lists publications by classifying them by taxonomy
- Custom post type archive page filters
- Display related CPT with custom taxonomy
- Filtering posts based on three taxonomies
- How to output custom post type title on custom page with category next to it?
- get taxonomies from terms
- Display Custom Post Type Based on Taxonomy With WP_Query()
- Create custom post type categories
- Set a Default CPT taxonomy by taxonomy id
- how to create custom taxonomy drop downs for parents and child
- How to manage a dynamic multi-level page hierearchy system?
- Custom Taxonomy – fields
- Custom Post By Category
- Categories manage
- One of my headings is mysteriously coming up as a link in my CPT Archive
- Only show categories that have posts within custom post type
- Query the title of the page to show posts with matching category in the loop
- Reuse the “category” slug for a custom post type
- Query for a custom post taxonomy
- How to create groups like that in buddypress?
- Only show current category post
- Update Cateogory Taxonomy Count for Attachment Post Type
- Can’t seem to filter wp_query by current category ID
- Custom Post Type + Category archive
- How to display elements of different post types?
- How can I set up the URL for a category archive for a custom post type?
- Custom Post Type order Title ASC
- Get all custom_post_type posts + blog posts from one category in a single query
- show only one category posts in admin
- Are custom posts included when getting a categories’ posts?
- Is it possible for post and custom post type to share a category base slug?
- How do I get parameters from the URL?