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
- Register custom query args parameter for WP_Query()
- 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
- 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 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?
- How to ensure “the_content” filter runs only for the main displayed content?
- Actions or filters fired when data is saved in a custom table
- Some nav-menu filters do nothing
- Determine which theme location a wp_get_nav_menu_items is for
- What’s the difference between hooks, filters and actions? [duplicate]
- Conditional add_filter?
- Calling apply_filters on non-documented hooks
- WordPress Media mime type filter problem 4.0
- How to add custom content under plugin row in WordPress admin plugin list?
- 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
- Cannot search post by taxonomy
- How to print raw query from WP_Query class just like in CodeIgniter
- WP_Query returns no results
- manage_posts_custom_column, showing serial number using increment in loop
- Two functions utilizing registration_errors filter
- 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
- 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
- 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
- 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
- How can I replace content in the WP Admin area before an admin page is rendered?
- how to use in custom single.php template using php?
- Search: how to extend the existing search to include a custom table
- How to filter content for specific content variable
- Valid filenames for add_action’s first parameter
- How do I access the menus produced by Dashboard > Appearance > Menus
- how to invoke wordpress API from other existing PHP system
- How I can use order by of the custom post title?
- How to get all queries’s results after they have executed?
- How to get the post excerpt using post object?
- 400 Bad Request, in wordpress theme development, wp_ajax
- Bind a function with its own argument to show something dynamically after every content
- Hook add_attachment error
- Update variable value via add_filter
- Make wordpress join default user metas with a column from another table while displaying the wp_users table on the users screen
- Configure WordPress to Generate Scheme-less Relative URLs
- Gravity Forms Anchor only on Front Page?
- How to find list of all functions bind to a particular hook from my plugin?
- Get Posts by IDs (optionally)
- How to get the number of pages when paginating comments?
- Adding filter to the title without affecting the menu title
- filter posts by meta key with pagination
- How to validate inputs with filter in register_setting callback
- How do i remove the title from a specific page
- Can / should a widget plugin define its own Widget Area?
- Is it possible to use the MySQL’s ORDER BY FIELD() clause as part of the pre_get_posts hook?
- apply_filters() and call_user_func() to define and call a function outside a class
- add_filter postbox_classes multiple post types
- Override category archive page title (not the head title)
- WP_Query not ordering correctly
- Override woocommerce loop-start.php from theme using plugin?
- User meta query using Wildcard
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- WP Query date_query with several date range
- Change Front page displays settings conditionally when user is online
- Add_action not calling callback function
- I have a plugin where in I have to change the title of the page dynamically by sending parameter to the_title filter
- get_comment_meta() for a filter hook in a plugin
- Post Pagination does not working on WP-Query
- WP Query Relations / Compare
- How can I query 3 posts from diferente categories (one of each category)
- Custom signature appears twice on page
- Caption Shortcode: what filter to change the image size?
- Hook for plugin to show content for certain urls
- Get custom wp_query search results to appear on search.php
- How do I replace title with my plugin?
- wp_mail_from not changing from address
- append code after the_content not working
- What is the meta_query key name for the woo product average rating? [closed]
- get the queried_object of an url
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]
- filter on get_posts efficiently