The reason the menu is disappearing is because pre_get_posts
applies to all queries on the page, including menus, your code is interferring with the menu queries. The is_main_query method should make sure it only affect the query in the loop, which in most cases will be the query displaying the posts.
function test_add_cpt_to_archive_page( $query ) {
if ( $query->is_main_query() && $query->is_archive() && ! is_admin() ) {
$query->set( 'post_type', 'any' );
}
return $query;
}
Related Posts:
- Help with Multi Level Category Archive Page
- How to build a complex page structure
- Template tags to display custom post type posts in category template?
- Custom post type archive sorted and grouped by date in post meta field
- Categories and Tags not working!
- Display Next/Prev when looping Custom post-types archive?
- Should I use custom menu, C.P.T. or theme options, or something else for this?
- CPT Archive with core Category
- Custom post types and category archive
- Archieve.php not loading for custom post type
- Include custom post type custom taxonomies in Categories widget
- Custom Post Type Custom Archive Page Not Working
- Custom post type category permalinks and archive pages
- 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
- Custom post category name showing empty
- Getting Same Description in All the Custom Taxonomy Posts
- Custom Post Type archive page listing a 404 or single post
- Only show categories that have posts within custom post type
- Custom post types not displaying per category
- How to Show all Values in category.php page using post_type
- How To Display Category list from Portfolio post type plugin?
- Having some trouble properly displaying Custom Post Types in templates
- How can I set up the URL for a category archive for a custom post type?
- Category names on CPT archive pages [closed]
- Custom template won’t load for a custom post type (custom permalinks used)
- Group posts by custom post type
- What’s the difference between same wp functions get_posts(); functions in different form?
- Set up Custom-Post-Type Author Archive
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Display all posts in main category and 1 subcategory
- Replace li Items with divs with classes
- showing custom post types of a certain category only
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- Get posts from a custom post type by child categories of a parent category
- Linking to the most recent post in a Custom Post Type
- Custom Post Type Archive Page Filtering
- Getting posts under the custom post type ui category
- Show category ID on custom post type
- How can I auto-assign a CPT post to category in a custom taxonomy when published?
- What template files do I need to customise custom-category-term-links rather than fall back on archive.php?
- Unable to get post archive link
- get the custom post type title/name
- get_posts() with custom post type does not work outside page.php
- CPT custom archive template does not get loaded
- Posts from all the categories are being displayed instead of particular category
- Get parent categories of custom post type
- Custom post types and tag archive pages/permalink structure issue
- Custom post type templating problem
- Custom post type is showing custom home page, not archive page
- How to query_post custom posts within default taxonomy?
- Conditional Statement custom post type category
- Show custom post type filtered by category
- Displaying Page as Custom Post type landing Page
- Custom Post Type With Categories
- URL of a custom post type’s post format archive?
- Custom Post Type archive loop separated by term, in specific term order
- Display posts from Custom Post Type in category page on front-end
- Show only posts from one category on custom post type archive page
- Get term name and term parent into custom post type permalink
- Categories sorting
- How can I make my custom posts appear in their assigned category url?
- How to call in Custom Post-Type Categories?
- Allow user to set custom order to a list of custom taxonomies?
- get_category_parents for custom post type taxonomy
- Separate custom categories from default category
- Create template for taxonomy results limited by Custom Post Type
- forming WP_Query for posts of all post types but from specific categories
- How should I structure my post types?
- wp_list_categories() – current-cat class also inside posts?
- Showing posts from different categories and from custom post type
- Custom post type getting wrong categories and tags
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Help need making decision. Ads rotating site on wordpress
- Extending AZIndex plugin to use custom post types and custom taxonomies
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- How to use has_archive but disable feed per post type?
- Query & Order posts by custom fields
- Show a Category X’s custom post type on Category X archive page?
- custom taxonamy and post type
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Custom post type: Disable single page, but keep archive
- WordPress post_where & posts_join not working only for custom post type
- PHP variable not regenerating when publishing multiple posts at the same time
- Multiple level category drop-down from the WordPress dashboard
- Return the latest post from a custom Taxonomy and Post Type
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Don’t know how to show custom taxonomies from a custom post_type
- Add custom post type settings to wordress default posts
- Use Custom Post Type archive page for the taxonomies term archive page
- Display custom post type category, while in a CPT category, then the posts beneath
- Hide parent categories when clicked, and show it’s childs
- Limit amount of posts made within a custom taxonomy
- Problem with displaying posts in the CPT category
- Not Able to Get Custom Post Type Gallery Images URL
- Filter CPT posts by one or more categories
- Getting categories of posts under a custom taxonomy
- JS innerhtml changing style when using AJAX
- Custom Post Types with a common category for a blog listing