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
- Row actions for custom post types?
- remove custom post type permalink
- Saving Taxonomy Terms
- Filter by custom field in custom post type on admin page
- How can I remove the “Add New” button in my custom post type?
- Media library – Limit images to custom post type
- Sort search results by post type
- How to order posts of a custom post type by date DESC in dashboard Admin?
- How to remove Filters from post admin page?
- Custom sortable columns ordered by meta-value?
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- How to completely disable a taxonomy archive on the frontend?
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Query when is one or several values
- Is there any filter to add a custom attribute to the tag in admin panel?
- Display category filters for custom post type when category is shared by multiple post types
- Store a value in global scope after init hook is fired
- Filter in Custom post type to find the parent post
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- Dynamic page for nav items used as filters
- Create Post Types from a XML url (Real Estate website)
- Filter posts by their related field’s custom field
- Post Click Redirect to Custom URL instead of Single Post Page
- How can I add image sizes for a specific custom post type?
- Add content to wordpress edit.php page
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- add_rewrite_tag broke permalinks that doesn’t use that specific tag
- pricefilter without WooCommerce
- Output all terms slugs for a loop filter
- Insert custom taxonomy into category query
- filter rest api post by a acf filed
- Group Custom Posts Types in a Relation field of ACF
- Help Adding filter to Add Media button for custom post type
- I can not call the categories of custom post type
- Apply pre_get_posts to specific custom post type in the admin area
- how it’s possible to show from a post of a custom post type the taxonomy/terms?
- Keep br tags from stripping
- Add filter button to custom post type in admin area
- Enable shortcodes on custom post type
- Filter between Custom Posts depending on meta_value
- Change Background Color For CPT Template
- Grouping and paging CPT events by month with custom field date
- WordPress add taxonomies/terms list as a menu in archive page
- Highlight a Post on archive page if it has a new comment?
- Creating adminable dynamic filtering on custom post type
- Adding CPT changes entire layout of my site except for the archive of that CPT
- Adding Information To All Posts Screen
- Menu disappears with custom post type link
- Dropdown switching subcategories portfolio
- Filter Content on all Post Types
- Filter wp_dropdown_categories Per Post Type
- Custom post type with Filter and Page Nav
- getting a blank login page :( any way I can fix this without having to do a clean install?
- How to get main div html to print a list of posts inside?
- erase post excerpt limitation [×]
- Sorting on Taxonomy in archive page
- Converting a checkbox filter for custom fields to a dropdown
- How to get $post object available inside functions.php to localize script?
- add current-menu-item to multiple custom post types
- Filter custom post type by tags
- Query custom post type and showing its content
- Custom Search Template for Custom Post Types
- Exclude Custom Post Type from shared Custom Taxonomy
- using ACF datepicker to filter posts on a page
- Hook only specific post type
- Restrict a filter to a custom post type. Am I doing this right?
- Diffrent search templates for different post types
- How to filter posts by categories?
- Problems with a custom meta_box
- Create custom post order (with custom post type meta)
- Query by post type or category
- Change position of Post Formats box?
- How do I filter a custom post type loop by a field?
- A to Z list for custom post types
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- How to manage wordpress knowledge base/wiki/posts collections
- add_filter > posts_where works partially
- Simple Share Buttons Add Plugin and Custom Post Type
- How to get ‘Products’ on home page?
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Trying to set up a range filter for related custom post types
- Filter page ID outside the loop and order
- how to display custom taxonomies in front page
- REQUIRED: The theme uses the register_post_type() function, which is plugin-territory
- When Attempting to Filter Plugin Generated Content Using Filter post_type_link, Permalinks Are Not Modified
- 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
- Add post id to url instead of WordPress default -2 suffix
- coloring row’s background based on custom field value
- Custom post type template not loading from plugin
- 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?
- Modify wp_title for custom post types using custom fields data?
- How do I add a filter to my custom post type archive page?
- How to Filter the Custom term loop based on dropdown
- WordPress commercial theme cancels default functionality