The amazing @Krzysiek Dróżdż was right on the money on this one!
I can’t believe nobody has picked it up until now.
The code I was using has been shared on all sorts of well-known/well-referenced sites, as is, and NOBODY has fixed it to include is_main_query.
Revised code, for anybody else who’s searching:
// Add New Custom Post Types to Archives
function rtt_add_cpts_to_archives( $query ) {
if( $query->is_main_query() && is_category() || is_tag() || is_author() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array( 'post', 'nav_menu_item', 'work', 'event', 'news', 'newsletter' ) );
return $query;
}
}
add_filter( 'pre_get_posts', 'rtt_add_cpts_to_archives' );
Related Posts:
- Filtering a custom post type by custom taxonomy in archive template
- Why are posts from custom post type not displayed in “category” archive?
- Displaying category archive of custom post types
- Regex problem in an add_rewrite_rule
- get_categories for custom post type and filter by custom taxonomy (brand) and list child categories of a defined category
- Category page only displaying the posts from a custom type
- custom taxonomy archive by year
- CPT Archive with core Category
- Custom Post Type Archive Page Filtering
- Archieve.php not loading for custom post type
- multiple custom post type on category page
- Archive Template being used instead of Category Template for Custom Post Type
- Menu’s breaking, now showing all page links on site
- Advanced archive url structure (category, tag and date)
- Display all Categories except ones with a specific parent
- Custom WordPress theme not displaying posts from category
- Custom category taxonomy – archive page not showing up
- How can I generate a list of post-type specific categories?
- Custom Post type archives / categories give 404
- archive.php can’t find categorized posts
- How can I set up the URL for a category archive for a custom post type?
- Categories in custom post types
- Stop header code from showing in category page?
- Get custom post type slug for an archive page
- How can I list all the categories under a Custom Post Type (taxonomy)?
- Custom Post Type Archives by Date with Custom Permalink
- category__in not working on custom post type
- how do I group content in magazine-style ‘issues’?
- Use standard WordPress categories with a CPT
- Change plugin’s has_archive = true to false?
- How can I add single catogory for custom post type?
- Get the post_type of current taxonomy or category page
- Categories and Tags not working!
- automatically save custom post type title as a category
- Slug for standard post post_type
- WordPress custom post type archive with description
- Get post type from taxonomy or category page
- get_categories() for only CPT
- category.php displays ALL posts instead of just those with the current category
- Display Next/Prev when looping Custom post-types archive?
- When ‘is_post_type_archive()’ return true?
- Possible for Category Base and Custom post Type to share the same slug/permalink?
- Weird problem happening with custom taxonmy when creating/updating posts
- How to detect filter in URL in Category page?
- Replace li Items with divs with classes
- showing custom post types of a certain category only
- Get posts from a custom post type by child categories of a parent category
- get_posts() with custom post type does not work outside page.php
- Tag Archive for Custom-Post-Type Posts yielding 404 when permalinks set to postname
- Show a Category X’s custom post type on Category X archive page?
- Multiple level category drop-down from the WordPress dashboard
- Getting categories of posts under a custom taxonomy
- How to get categories linked in posts for a specific post type
- WordPress showing archive.php instead page
- How to edit this code to get the categories in achieve page?
- Get the category from custom post type
- How to create a gallery page with categories?
- Cross reference custom post types
- Make a custom_post translatable
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Custom templates for a specific category
- How to retrieve category of a post in have_post loop?
- Get parent category id from child category page for custom taxonomy
- Disable custom taxonomy on admin bar
- Assign CPT archive page attributes
- Want a custom query with just one category but from all custom post types
- Display Date & Author Info on Custom Post Type Archive Page
- How to constrain the results to a specific post_type on tag archive page?
- Custom Post Type with modified permalink structure results in 404
- Custom post not appearing under custom taxonomy category
- How to prevent a custom post type from using the archive.php template?
- If custom category search then page 2 not found
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category
- Show the categories the current post has
- Custom post type data not displaying If I select the category from the dropdonw
- Custom Post type page content (archive page)
- 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
- Custom post types not showing on the standard WordPress Category page
- Get posts in custom post type categories
- Do not load the categories in Category.php
- Turning archive templates to a page template maintaining the slug
- Use Category for Custom Post Type – But Need Another Separate Archive Page too
- Only show current category post
- how to use two permalinks for one custom post type based on categories
- Rewriting archive page slug to be different than custom post type slug
- Site loads very slow for archive custom post type page
- Custom Catagory not found
- Page to show custom posts and one category
- How can I list custom post by custom category?
- how to show perticular category posts in custome page
- Bulk remove category from custom post type?
- Problem with menu categories doubling up when updating database?
- Remove slug from Custom Category Permalink + dual-category permalinks
- How to query posts by category with the_title();
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Show custom category archive as front page and remove taxonomy slug from urls
- Categorizing Custom Posts in Bulk Based on Title