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]
- How to change permalink structure for custom post type and it’s taxonomies?
- Change permalinks for posts but not for custom post types
- Assign single template to multiple custom post types?
- Proper way of making custom post type landing page or archive page
- Custom Post Type Archives with 0 Posts Redirects as 404
- Get categories for a specific post – Custom post type
- How to get_queried_object on multiple objects?
- Rename a current used post type
- Include custom post types in categories widget
- Assign Page Template Within A Custom Post Type
- Custom Post Type – Archive page title
- Listing and accessing categories for a custom post type
- New WP_query in template not working with CPT+category on some pages
- Getting taxonomy terms used by custom post type
- Taxonomy list. Order by a specific custom post type count
- Categories not working as expected with custom post type
- adding .current* tags to custom post types and taxonomies
- I am facing problem in my archive page , it is partially working
- taxonomy template for custom post type the same as the archive
- Get categories and descriptions from custom post type
- How to create new category for custom post type?
- Conditional tags don’t work
- How to show CPTs in term archive
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- How can I auto-assign a CPT post to category in a custom taxonomy when published?
- Help need making decision. Ads rotating site on wordpress
- Categories of custom taxonomy don’t show any posts
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Use Custom Post Type archive page for the taxonomies term archive page
- Number of Custom Post Types published are not being shown in the custom page
- posttype/taxonomy/term archive page 404 error
- List of Posts and Categories
- Set featured image to archive.php
- Getting used tags per post type
- Why does accessing url by category cause issues with post types?
- Custom WP_Query doesn’t display all posts
- How can I use archive-{post_type}.php theme template?
- Custom meta Title for custom post type archive from page
- Navigate posts with different post type that are in the same categories
- Why does my taxonomy have a category style div id?
- Alphabetically sort a taxonomy.php template by post title
- Show Taxonomies with admin area for custom post type?
- Custom Post type date archive for custom taxonomy
- Restrict category access to specific users/groups. Author always has access
- get_terms() parent, child and grandchild
- Getting custom taxonomy posts on archive page
- 4 posts per page from single category
- Menu’s breaking, now showing all page links on site
- Pages not appearing?
- Not Able to Add New Class To CPT Attachment Image
- Add extra elements to the_post in a custom post_type
- Visualize info in just custom post_type in theme
- Cannot use object of type WP_Error as array display category
- cpt not display inside nav menu
- Issue on Getting URL of Uploaded Image to a Custom Post Type
- Cannot get to work tax_query array for terms
- Display Custom Post Type Archive content with Shortcode
- Too many revision when post status is changes [duplicate]
- Unsure what page hierarchy to use with CPT UI to show on front end
- Loop through a specific parent category
- get first limited words from a custom post in the archive page
- Query the title of the page to show posts with matching category in the loop
- creating a custom post template
- 2 custom posts types, in their own columns, one pagination for both
- Show index and not the archive for “Dog Custom Post” with default slug
- Making a archive gallery page for a custom post type which already has an archive page
- Custom post type URL – filter by taxonomy
- How to query all custom posts of a certain type and checking what category they have
- Post Editor: display categories from current post type taxonomy only?
- Customize category URL
- Custom post type and category permalinks
- Bulk edit for custom taxonomy
- show only one category posts in admin
- display all posts in current category
- WordPress search results grouped by post type