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
- Query Custom Post Type taxonomy type based on page
- 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
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- 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?
- tax_query returning all posts instead of selective posts in WP_Query
- Querying Term Posts in Loop
- How to create new category for custom post type?
- Fetch taxonomies by custom post type id array
- Get Post Primary Category
- 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
- forming WP_Query for posts of all post types but from specific categories
- 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?
- Limit amount of posts made within a custom taxonomy
- Several post types on WP Query by tag and taxonomy
- WP Query with categories only shows one post and ignores the category
- Why is my category template ignoring post type?
- 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
- Redirect to another page using contact form 7? [closed]
- WP the_posts() on single-cars.php get category link
- Categories and tags for custom post types
- WP_Query Custom Post Type if Category ID Equals
- Custom post types and ‘new WP_Query’
- 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
- List categories, subcategories and posts from custom taxonomy and custom post type
- 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
- Sort results without WP_QUERY?
- How to create groups like that in buddypress?
- Only show current category post
- Update Cateogory Taxonomy Count for Attachment Post Type
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Can’t seem to filter wp_query by current category ID
- Custom Post Type + Category archive
- Best way to structure article and issue relationship for CPT
- Custom Post Type used for FAQs Accordion
- 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
- Using tax_query to get single post per category
- show only one category posts in admin
- Are custom posts included when getting a categories’ posts?
- Is it possible to make is_category() recursive?
- Is it possible for post and custom post type to share a category base slug?
- How do I get parameters from the URL?
- WP Query filtering by custom category not showing all relevant posts
- Category display using conditions
- How to display posts from home page in blogs in category wise
- Separate archive template to show posts and CPT by same category/taxonomy
- Add taxonomy or category slug to custom post types URL
- How to determ a custom post type url?