Use is_main_query()
to modify only the main query so menu will stay not affected.
Try This:
add_action( 'pre_get_posts', 'fteh_pre_get_posts' );
function fteh_pre_get_posts( $query ){
if( !is_admin() && $query->is_main_query() && isset( $query->query_vars['type'] ) )
$types = explode( ',', $query->query_vars['type'] );
$query->set( 'post_type', $types );
return $query;
}
Related Posts:
- Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?
- Dynamically exclude menu items from wp_nav_menu
- Add custom menu item using wp_nav_menu_items filter
- Unregister Nav Menu from Child-Theme
- Allow html tags in WordPress Custom Menus Description Field
- Using filters to change href of nav menu page link
- How to apply a class to the second word in menu list item?
- wp_nav_menu() not working on Custom Search Page
- WordPress nav_menu_link_attributes Not Working
- Is it possible to add a filter for the output of nav-menu items in admin?
- if role is logged in then do something
- How to limit search to first letter of title?
- Search pre_get_posts filter which can handle multiple post types and categories?
- Filter menu item to add classes/attributes?
- Edit html for menu items in default frontend menu
- WordPress Search Filter Only for Page with Child of Child of Child of Child of Child
- Set Item Order with wp_nav_menu_{$menu->slug}_items
- When at / ( or “home”) my menu doesn’t get a current-menu-item class
- How to add parent element’s title to nav menu’s child?
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Add class to active element and its parent in nav menu
- display only the wp_nav_menu, which has the current-menu-item
- Where do custom menus get constructed?
- Search by type posts and taxonomy
- Removing strip_tags not working on nav_menu_description
- Third level navigation class
- How to add #navbar to all page links?
- Create search form in menu as in Twenty Fourteen theme
- get_search_form() doesn’t appear to take parameter into account
- add span to top level links of a wordpress menu called “main”
- Input type search in Menu
- Debugging – trying to add search box to menus
- wp_list_pages() but only show children on the branch you are on
- From a page, is it possible to find entry’s “menu_item_parent”?
- Add active class to top-level menu items when viewing single for that post type
- Custom Links menu items include in Search Results
- add_filter on menu items to add a menu item
- how to disable default menu classes
- Insert other menus as submenus of a main menu
- list category posts under its item in menu
- Prevent menu from loading in a page template [duplicate]
- Insert a div before the wp_nav_menu
- How to change menu structure?
- Secondary Navigation Menudisappeared When using wp_nav_menu_items
- remove specific classes from menu items
- wp_nav_menu action/filter help
- add_filter for where statment issue
- Add a counter beside menu item label
- Add custom link on the fly to nav menu
- How to add search to menu?
- menu-item class missing on wordpress menu
- Filter to hook into menu items and add a custom attribute
- search form leads to 404
- Search form as list item in menu?
- Amend taxonomy to search in wordpress admin
- pre_get_posts fix to show menu on CPT Archives broken WP 6.0
- if role is logged in then do something
- Possible to append class to nav menu added to widget area?
- Modifying Woocommerce menu based on tags and categories
- Admin: WooCommerce Navigation Menus do not show empty categories search tab
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Menu location switcher – example code fails
- Add Featured Image and Title to wp_nav_menu items
- Show thumbnail to category items in wp_nav_menu(), how?
- Add Class to Custom Menu Widget ul
- Avoid changing menu query with suppress_filters => false
- Removing menu item doesn’t get removed on edit post
- Add Protocol to Custom Menus
- How to modify menu text in callback function of ‘walker_nav_menu_start_el’ hook
- Filter posts by multiple checkbox categories
- How To Add Class To Style Search Box
- After WordPress 4.8 upgrade, wp_nav_menu() string search / replace not working
- Why is WordPress stripping anchor links from mneu item URLs?
- Hiding Widget On Mobile Devices Removes Our Product Search Box On Mobiles
- Add button and title on submenu WordPress
- How to change order of menu items
- Add Commas Between Menu Items?
- Make compatible custom menu widget for Twitter Bootstrap
- Variables within wp_nav_menu
- wp_update_nav_menu_item not saving in multisite API
- Header style different on home and remaining pages
- display menus on all page except one?
- How Do I Add Images To Main Navigation Menu
- query_posts() – problem with “s” parameter
- Is it still not possible to show separate submenu with “Custom Menu”?
- Rename the label on a menu location which is already defined?
- How to making dynamic URLs for menus in WordPress?
- Best way to create a search for custom post type by custom field values
- How to change the menu like this?
- Removing Submenu from Menu
- Custom link missing as option in my ‘add menu items’
- Can’t add optional class to menu item when using Walker_Nav_Menu
- Theme: Twenty Thirteen Mobile Sliding Menu Doesn’t Bump Content Down
- Database structure Menu Item
- Active Navigation Class Based on URL on icon
- Rename Menu icon in Twenty seventeen theme
- WordPress Menu – Adding a new dynamic element to the menu
- One item on menu is not clickable when it should be
- Critical Error when editing menu
- I need to change the hyperlink attached to the logo on the mobile menu