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:
- Update plugin from personal API
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- Symlinked plugin directory doesn’t appear in Admin
- Where the Nickname is being used in WordPress
- enqueue script only if it is not already enqueue
- How can I limit functionality in one version of a plugin?
- How can I include a setting that has a variable number of values in a settings page using register_setting?
- Custom data-id wp_enqueue_script
- Yoast SEO blocking/re-initialising longer running process
- Add Fields with Sub-Fields to WP Job Manager
- template_redirect not being called when using ajax
- How use %like% in sql statement wordpress
- Can I use a form in a dashboard widget?
- Is there a way to alter the order in which the plugins appear in the page?
- How to correctly detect accessing wp-content/uploads?
- Retrieving plugin options value saved through setting
- How to ‘clone’ a wp plugin to make small changes
- MITM risk of not sanitizing?
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- Simple ajax call not working in wordpress plugin
- Plugin Options Not Saving to Database in WP 4.5
- How to save post change url youtube link?
- __callStatic method handler passed to add_action causes bug in PHP
- how to disable blockrenderAppender inside all Innerblocks?
- Redirection of users away from wp-admin (but not administrators)
- New databes tables with – WooCommerce – for developers [closed]
- Plugin-generated pages use Not Found or Pages Archive templates?
- Change commission_status paid when withdraw_status vendor is completed
- WordPress Plugin [closed]
- Proper way to replace the_content only for pages created by custom plugin
- Certain functions are undefined when called form mu-plugins
- Why is the ‘Gutenberg’ Plugin generating an ‘Inconsistent File Permissions’ error when other Plugins, with the same permissions, do not?
- Can plugin2 uninstall plugin1 at the very beginning of plugin2’s installation?
- WordPress front end AJAX. Return 0 :?
- plugin dev – minimum base css specificity?
- I changed font of wordpress dashboard but it is slow!
- Get Every Key & Value from Array then Display All in New Line
- WordPress 5.4 – How to prevent to enter only certain values in custom field
- Creating a functionality plugin to edit seriously simple podcasting
- Plugin temporary files and files to download via FTP
- DB Query not working in Plugin
- Make plugin php file called directly aware of WordPress?
- sending different email notification while registration based on user role
- How to add credit card validation check to wordpress [closed]
- Next Previous Post in wordpress with previous / next link with title?
- How to use existing hook in twentytwelve to all theme of wordpress?
- How to get a notification when the plugin is installed?
- WordPress Post HTML after Posting
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Settings options not showing up on Sub Menu page in WordPress plugin
- unregister a sidebar widget
- How to Get Category Name When Export Products
- Remove List Bullets
- Custom Meta box change size
- Could add_query_arg() redirect user to external site?
- How to set plugin auto-update Enabled by default?
- Custom plugin activation error
- The Build menu theme is frozen with the wordpress theme
- How to capture hidden values with Gravity Forms
- How to translate to spanish wordpress hardcoded content/files?
- what functions to use to resize images and create DB metadata for them after/during upload?
- Multiple image selection custom widget
- How to Create a Learning Management Plugin in WordPress to Manage Courses [LMS]
- How to prevent redoing get_posts queries and make results available to other scripts?
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Paid Membership Pro displaying a user name in PHP
- Make another copy of a plugin and install it
- Store admin page into variable
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- WP Plugin CSS not being applied to page
- Overwriting Plugin’s Ajax callback function from theme
- How can I get the Post ID and Post Type within a Must Use Plugin?
- Creating Nested custom fields
- Unable to sync woocommerce variations
- Can’t find variable is_single in my jQuery plugin
- WordPress Cron function is not working
- WP internationalization not loaded
- Plugin hook breaks new WP 4.0 media library grid view?
- How to get site homepage from plugin?
- Adding custom cron_schedule prior to wp_schedule_event
- Create plugin with form in post and submit it to specific form
- Storing values in Post Meta vs new tables
- Get page type to display content
- Widget redirecting to home page
- Capturing POST data
- Is an Office a custom post type [closed]
- How to add image for custom taxonomy
- I am using multi image metabox plugin but I did get how to display the images in templete?
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- wordpress Ajax success doesn’t return the value
- How to open author url linked to a new tab in settings page in the WordPress plugin list
- How can I properly sanitize the update_option in WordPress?
- Why is my menu page not being displayed?
- WP Elementor Pro causing crtical failure on website
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Wrong block appender button showing
- Uncaught Error: Cannot use object of type stdClass while showing the list using WP_List_Table
- plugin doesn’t retrieve data from database
- Display Any Field fromAdmin Panel in Frontend via Shortcode?