At the pre_get_posts
action, check if the query object is_main_query
to target only the main archive query and exclude additional queries.
add_action('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if($query->is_main_query()
&& ( is_category() || is_tag() )) {
$query->set( 'post_type', array('post','cpt') );
}
}
Related Posts:
- Custom Post Type Archives by Year & Month?
- Get custom post type slug for an archive page
- Custom Post Type Settings page, choose page to display archive
- Adding a menu item for a Custom Post Archive
- Adding custom post type archives to a WordPress menu
- How to set a custom post type to have viewable future posts
- How do you create an archive for a custom post type from a plugin?
- Custom Post Type Archives by Date with Custom Permalink
- Change title in head on Archive page
- How to filter custom post type archive by meta value
- What are the advantages of using a custom post type archive?
- “Edit” option for custom post types archive page
- Custom Post Type archive as front page
- Custom Post Type / Taxonomy Slug / Post Title with post type archive
- Adding Sticky functionality to Custom Post Type Archives
- paginate function in archive for custom-post-type
- Archive page for taxonomy of custom post type
- archive-{$post_type}.php not loading. instead the default archive.php loads
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- How to make an archive page displaying posts in a date range
- Categories and Tags not working!
- Custom query variable – get wordpress to redirect to nice permalink url
- WordPress custom post type archive with description
- Display Next/Prev when looping Custom post-types archive?
- Archive page for custom post type not working
- Editable content on a Custom Archive page
- Second Custom Post Type Archive
- How can I filter by taxonomy on a custom post type’s page?
- An empty Custom Post Type Archive page returns 404 in WP 3.1
- is_main_query() not working for WP REST API
- CPT Archive with core Category
- Set up Custom-Post-Type Author Archive
- get the custom post type title/name
- Custom post types and tag archive pages/permalink structure issue
- Custom post type templating problem
- Displaying Page as Custom Post type landing Page
- WordPress post_where & posts_join not working only for custom post type
- Single post with a Custom Post Type returns 404, when archives of the CPT work correctly
- CPT archive admin menu label
- Custom post type archive page blank
- Creating a Custom Post Type
- Custom Post Type slug same as page name
- Content Editable CPT Archive?
- Paginate_links in custom post type template
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- How to hyperlink content from archive page with custom post-type
- How to set up Custom Post Type archive page as Front page
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- sort CPT on Custom Taxonomy Archive page
- ACF for custom post type archive pages: which hook to use?
- CPT Archive pre_get_posts not working?
- Removed custom post type archive page shows blog page
- Plain links in single-class.php and archive-class.php not working
- add_action ‘init’ from inside a class for custom post types
- Custom post type archive – error in nav-menu-template.php
- Make Next and Previous on single-$posttype.php use the same order as archive-$posttype.php
- CPT archive page – show one post from each taxonomy term
- Get single posts archive information
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- Specifying a template for custom post type pages
- How to set a ‘page’ as parent of a custom post type?
- Invalid content when I try to import custom post type from the old template wordpress
- 2 Custom Post Types In 1 Archive Page?
- Different number posts per page based on custom post type term id
- Does this archive template part look like its making too many calls to the db?
- Finding the CPT archive template source
- Displaying all posts by category and showing content on click
- Custom Post type page content (archive page)
- Posts per Page on custom Taxonomy Template
- Group custom post type posts by month
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Tell wordpress to show a single page instead of an archive page
- Custom post pagination not working
- Custom Post Type / Taxonomy / Term – what template to use to avoid 404-page?
- get_permalink() of page the enclosing page not posts
- How to manage a custom post type archive as a page?
- Custom post type post_type_link gives “page not found” on any other custom post type
- How do I get the posts from single page custom post type from a sidebar to display in a page?
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- How do I make my archive page look like popular reviewing sites (e.g., Polygon and Gamespot) [closed]
- Rewriting archive page slug to be different than custom post type slug
- Custom post types archive
- Site loads very slow for archive custom post type page
- Remove the “View” Link in Post edit Admin
- Have two (permalinks) urls for a same custom post type
- How to display the FAQ Archive page in my menu
- Rewrite rules causing hole
- How can I set up the URL for a category archive for a custom post type?
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- Create a Page Templete to Display Table Of Content for Custom Taxonomies
- How to have a dynamic slug and rendering the archive-{post_type}.php?
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- Show custom post type on post category page doesn’t work / breaks navigation
- On archive.php show loop for child categories if they exist or posts if they don’t, on custom post type
- Pagination not working on custom post type archive
- Best practice to display a list/archive of Custom Posts in a Page Template
- Archive pagination – second page shows exactly the same posts
- Dynamic WordPress rewrite rules for multiple custom post types
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query