Use pre_get_posts
filter & use is_main_query()
function to check for the context (as you’ve figured out in the conversation with @Milo), however, don’t use is_main_query()
directly.
When you use is_main_query()
to check the context, it always checks against the main global $wp_query
, instead of another custom query object you may want. So it may cause unexpected behaviour.
To make sure you are filtering the correct context, use the $query
parameter that’s passed to the callback function of pre_get_posts
filter hook. So instead of checking is_main_query()
, you’ll be checking $query->is_main_query()
. For example:
function wpse_example_filter( $query ) {
if ( is_admin() && $query->is_main_query() ) {
// $query modification CODE
}
}
add_action( 'pre_get_posts', 'wpse_example_filter' );
Related Posts:
- working code, not working – Plugin Dev
- Allow members to create groups on my site
- category page multiple products add to cart any plugin available for woocommerce
- WordPress UPDATE queries on MySQL database stuck
- Cannot view Custom Post Type no matter what I try
- How to remove WordPress Default Comment? not Facebook
- SimpleXML is not working with xml response from external api
- How to use Datatable with Ajax when creating plugin on WordPress?
- Custom Plugin Update
- Getting all woocommerce products from REST API call in plugin
- Creating one user access account for all the multiple sites
- is it possible to fetch data from a remote api while admin is writing a new post?
- how override a define
- WordPress plugin blog creation
- How do I stop plugins and themes from getting updated in a new plugin?
- Preserving existing functionality converting HTML to WordPress
- I enabled debugging but I still get the same message: There has been a critical error on your website
- Problem with wordpress has_action() function
- wp_mail function not working in WordPress Plugin Boilerplate
- How come W3TC is allowed to host premium code in the WordPress repo?
- When/where would want to attach other classes to the base class in a WordPress plugin?
- Link custom post type to page
- Offering a freemium plugin (a free version + paid version)
- Using id to show item
- add tags to wordpress post using REST API
- Multiple image selection custom widget
- implement checkbox or toggle switch in plugin code
- 500 Internal server error wp_handle_upload_prefilter
- path of wp-content directory when we are on some plugin
- Using foreach loop for `$instance` of form and update array widget iteration
- How to use wp_editor and save its data in wp_posts table
- How to call a function from inside class to outside class
- My WordPress activation hook isn’t working
- How to Create a Learning Management Plugin in WordPress to Manage Courses [LMS]
- “Enable Media Replace” plugin does not update serialized object in WPMeta
- One time call to external API in widget
- when i activate my WordPress plugin cannot see customizer options or preview
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- How to prevent redoing get_posts queries and make results available to other scripts?
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Loading plugin script only on required page?
- Update a previous version of plugin when the new plugin is built from the scratch
- Change Woo Custom Endpoint Titles from a Plugin
- Create survey that redirects to sidebar menu customized to answers
- How to write different events from different functions in my file to a log file in WordPress
- Create a form and have custom menu display based on user answers?
- How to define the slug for my custom plugin?
- Nested Actions and Filters
- Custom wp_list_tables redirect on specfic page
- Custom plugin settings page with tab. Error: “Sorry, you are not allowed to access this page.”
- return bbp_get_topic_author_id as integer
- AJAX update fails for public/non-admin users
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- I am Getting Sorry, no posts matched your criteria on form submit only for certain page [duplicate]
- Use Case: Multiple Shipping Methods per Order
- Showing how many times is plugin activated or deactivated
- wp_remote_post To external API multiple values with the same key
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- Passing function into add_action always returns the first argument
- Can’t access 3rd party API, code works on local server but not on wordpress
- wpdb update method is updating but not refreshing the current page data
- Shortcode and WP query using category attributes
- how to do Thematic like this website using wordpress?
- wordpress form not saving or updating
- Get a list of Product Categories inside a loop
- How to put a maximum real-time users limit
- Paid Membership Pro displaying a user name in PHP
- Installation failed, trying to install ANY plugin
- Securing a plugin pop-up window
- WordPress the_content Filter and GET Parameter
- Block content rendering on the top just below body tag
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- Load my Inline js footer area
- WordPress Thickbox Navigation Issue in Gallery
- Avoid WordPress header bar when form submission using admin_post in the frontend
- Set “Open in New tab” as default option
- Generate and send ICS file through WordPress
- Uploading images to custom table
- Get post content inside plugin class method
- How to make a plugin api route have permission?
- Changing author slug for a custom role without using plugin
- plugin operation launch every time i click on page
- Hook to display element as product on category page
- Function settings_fields() not recognized (Uncaught Error: Call to undefined function settings_fields())
- WordPress Product Detail and catalog
- Admin menu hilighting wrong item for CPT
- Custom author page for custom role
- Dynamic input fields in WordPress Plugin
- Custom role not listed
- Could someone maybe point me in the direction of a decent tutorial on how to create a wordpress plugin that is compatible with another plugin please?
- Custom plugin which downloads updates from custom endpoint, extracts new version zip into a new name
- Is admin section completely customizable in terms of styling?
- Make another copy of a plugin and install it
- Custom admin plugin read CSV
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Store admin page into variable
- Overwrite js code using WP_Footer
- Remove action added in plugin class from theme
- wc_get_product_terms() throws “Notice: Undefined offset: 0”
- Plugin Options Page and Subpage