That’s easy, pre_get_posts applies to all queries, not just those on the frontend. So if you don’t want it to run on admin queries, test if you’re in the admin and exit early!
You might also want to verify that you’re in the main query
add_filter( 'pre_get_posts', function( \WP_Query $query) {
if ( is_admin() ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
Remember, pre_get_posts runs on all queries, regardless of where, be it admin, frontend, XMLRPC, REST API, etc. It will only run on the frontend if you tell it to only run on the frontend.
Related Posts:
- single-{$post_type}-{slug}.php for custom post types
- Saving Taxonomy Terms
- Filter by custom field in custom post type on admin page
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- How to correctly get post type in a the_title filter
- How to add a CSS class to every image in a Custom Post Type
- Best way to filter featured image text for a custom post type?
- Why is get_post_format() for “Standard” returns empty
- WP Admin default view mode for Custom Post Type
- Custom post types and child theme
- post_type_link filter causes 404 on the CPT page it’s used on
- Password-protect a custom rss feed
- Make the ‘all’ filter default instead of ‘mine’ in a custom post type
- Exclude custom function content from certain pages
- Filter get_categories() for taxonomy term in WordPress
- Debug output during filter execution doesn’t work
- How to override parent theme function through the child theme [closed]
- Filter posts with ajax form and checkboxes
- Single Page WordPress CSS and JS links
- Unable to filter on field on edit.php page
- Help with issues on “Adding a Taxonomy Filter to Admin List for a Custom Post Type?”
- Adding posts of custom type into the main feed
- Used with meta_query in query_posts works slowly
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Add $more_link_text parameter to the_excerpt()
- How to get Custom Post ID by adding filter to child theme’s function
- Custom Taxonomy breaking pages permalinks
- How do I set the link in the Custom Post Type admin menu?
- I am trying to output portfolio items with a picture. This code doesn’t seem to be working. What am I doing wrong?
- How to filter out post type meta?
- How to check if “is single” page
- Modifying date filter on admin page for custom post type to link to custom field
- WooCommerce product search titles only
- How to detect filter in URL in Category page?
- Custom query to filter posts that have current post as a taxonomy [closed]
- Append date to custom post type url slug
- Genesis filterable portfolio isotope [closed]
- Filtering WP_Query
- filter custom post type by meta key in dashboard
- Categories of custom taxonomy don’t show any posts
- How to add a post slug to a url?
- WordPress sort search results by custom order
- Filter term taxonomy metabox in custom post type
- How can I made custom taxonomies relationship?
- WooCommerce sort products by the actual product width(not the shipping width)
- Loop filtering Custom Post Types and/or Categories
- search suggest – filter post type
- Filtering posts list table
- Migrating a taxonomy’s tags to the native category
- Adding custom image sizes and post types to a plugin or to a theme?
- Want to be able to sign up subscribers as authors
- Unable to set featured image
- Create new custom post and post category of same name
- Filter posts by tax (dropdown) and meta value
- Page Template Dropdown For Custom Post Types
- Custom post types problem
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- Should Custom post types and fields be in the theme files or in a custom plugin packed into the theme?
- Create a simple Testimonial page
- Methods for development wordpress themes [closed]
- Render a Post or Page using the correct file
- Modifying WP_Title For Custom Post Type
- Filtering the_content, but still need to display the unfiltered content inside filter
- Catch and display error on save_post action
- Is possible register two archive pages for single custom post type?
- custom filtering admin columns
- Ajax Post Filter | Split Taxonomy Into minPrice & maxPrice
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Query filter by value in meta_value array
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Display category filters for custom post type when category is shared by multiple post types
- Create Post Types from a XML url (Real Estate website)
- Post Click Redirect to Custom URL instead of Single Post Page
- Apply pre_get_posts to specific custom post type in the admin area
- Keep br tags from stripping
- Add filter button to custom post type in admin area
- Adding CPT changes entire layout of my site except for the archive of that CPT
- Adding Information To All Posts Screen
- Dropdown switching subcategories portfolio
- Filter Content on all Post Types
- Filter wp_dropdown_categories Per Post Type
- How to get main div html to print a list of posts inside?
- erase post excerpt limitation [×]
- Sorting on Taxonomy in archive page
- Filter custom post type by tags
- Custom Search Template for Custom Post Types
- Query by post type or category
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- add_filter > posts_where works partially
- Filter page ID outside the loop and order
- how to display custom taxonomies in front page
- Paginate yearly archives for a custom post type
- Change CPT Edit Target Link for Admin List
- How can I produce multiple webpages with a different output based on one entry/Page/custom Page?
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template
- coloring row’s background based on custom field value
- Show only taxonomy types terms associated with a custom post type in WordPress PHP
- How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?
- WordPress commercial theme cancels default functionality