The answer is to specify all the args on the add_filter() call, and then you can have both the array of posts and the query sent to the callback.
add_filter( ‘posts_results’, ‘do_stuff’, 10, 2 );
Related Posts:
- add_filter and remove_filter added before and after wp_query
- Pagination not working with custom wp_query
- Difference Between Filter and Action Hooks?
- How to create an API for my plugin?
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- WP_Query leaking absurd amounts of memory
- How can I load a page template from a plugin?
- Fatal error: Class ‘ms\WP_Query’ not found on plugin initialization [closed]
- Using query_vars filter
- Register custom query args parameter for WP_Query()
- How to add multiple custom URL variables?
- Getting wrong relationship value in $args in wp_Query?
- How to get Post ID with the Add Filter Function
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- Check for featured image in WP_Query
- add_filter OO with parameters
- Why Does get_posts() Return an Empty Set?
- How Can I Add a Filter to Class Instance Only?
- Is it possible to remove next-post / previous-post with out creating a custom template?
- How do I Make a Theme “plugin-ready”?
- How to remove unwanted panels inside InspectorControls from core blocks in Gutenberg
- function triggered by “manage_users_custom_column” filter not working
- Proper way to use apply_filters() with class functions?
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- How to ensure “the_content” filter runs only for the main displayed content?
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Some nav-menu filters do nothing
- How to get all images and their thumbnails from wp media library
- Filter on the_content ignores shortcodes
- Determine which theme location a wp_get_nav_menu_items is for
- How to change wordpress post title?
- Display only certain posts based on visitor’s country?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Conditional add_filter?
- How to create a dynamic page based on form data with a plugin?
- Is it possible to create an action hook using do_action() within add_action()?
- Hook for post permalink update
- Dynamically Override Fancy Title
- Calling apply_filters on non-documented hooks
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- WordPress Media mime type filter problem 4.0
- How to allow Unfiltered HTML in a wordpress multisite install
- How to add custom content under plugin row in WordPress admin plugin list?
- Changing bloginfo description from a plugin
- Handling form request from plugin file
- Is there a way to verified if an add_filter is already applied?
- Define a function outside a class and call the function using action or filter hook
- Does add_filter work outside functions.php
- Synchronize Custom post type tags to WordPress default posts tags
- Paging on a future post loop?
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- Cannot search post by taxonomy
- How to get orders with used coupon in WooCommerce
- WP_Query with tax_query, order by most ‘matches’
- How to print raw query from WP_Query class just like in CodeIgniter
- add_filter : Passing an array instead of the callback function?
- WP_Query returns no results
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- Finding posts containing matching array elements in a meta field usign WP_Query
- How to deal with equal & similar arguments for a function?
- Create a custom display order in the main menu
- WordPress after content Hook & external template part
- manage_posts_custom_column, showing serial number using increment in loop
- Error : “Cannot use object of type WP_Post as array in”
- Namespaced action and filter tags
- Proper way to run wp_query from inside a plugin
- Two functions utilizing registration_errors filter
- using new WP_Query in save_post function alters $post
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- WordPress is automatically linking plain text email addresses
- best practice for query string values – get_query_var always empty for my value supplied in query string
- get_current_screen() return null
- Slow WP_query due to nested wp_query. Need Suggestions
- Problem with parameters in url and pagination
- Problems with: manage_${post_type}_posts_columns
- How To Change Logout Screen Title
- ORDER BY wp_post custom column name in wp_query
- Add code inside specific wordpress standard function
- How to create database table, add data, update and delete using wpdb via plugins?
- Check for template part, else filter content
- Why doesn’t my simple the_title filter get applied?
- How to filter the_content() & include content from template
- Adding rewrite rule dynamically
- wp_query ‘s’, search filter with pagination is not working
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Replace youtube embed in wordpress
- WP_Query filters
- Can’t get woocommerce_get_price_html to work [closed]
- How to fetch only current hour posts?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Search and Filter
- WordPress pre_get_posts with combined results of two queries (OR)
- How can I replace content in the WP Admin area before an admin page is rendered?