You can access query variables (including custom ones) via the WP_Query::get()
method.
For example:
$my_query = new WP_Query( array(
...
'wpse105219_custom_var' => 'foobar',
...
) );
To ‘catch’ this at pre_get_posts
:
add_action( 'pre_get_posts', 'wpse105219_pre_get_posts', 10 );
function wpse105219_pre_get_posts( $query ){
if( $query->get( 'wpse105219_custom_var' ) == 'foobar' ){
//Alter $query
}
}
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- Should I use Pre Get Posts or WP_Query
- Using pre_get_posts with WP_Query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- What is “main query”? [duplicate]
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- wpquery via ajax
- Ajax (jquery) wp_query pagination returns -1
- How to pass the current content of $wp_query to a new page?
- tax_query in pre_get_posts
- $wp_query->found_posts not returning correct value
- WP_Query, Paginate by Custom Field
- Elementor posts custom query based on tag [closed]
- Exclude post with taxonomy and from the terms (taxonomy & tag) posts count
- JOIN filter doesn’t work in WP_Query in wp-ajax calls
- `offset` WP_Query argument dont work via `pre_get_posts`
- Replace wp_query with wp_user_query
- WordPress AJAX Request returns 400
- Block internal search queries with pre_get_posts and regex rules
- WordPress Ajax form filter | Search by title with ajax form, breaks the other filters
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- Why when I using infinity scroll the one post loads over and over?
- Using Ajax and WP_Query to load more posts on category page fails
- is_user_logged_in not working from WP-API (wp-json)
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- pre_get_posts pagination not working
- meta_query is overriding default search
- pre_user_query vs pre_get_posts
- Can I alter the main loop to ‘orderby’ a custom callback?
- order posts by a secondary query that counts items
- WordPress live search and filter custom fields
- WordPress live search and filter
- Filter admin ajax data by url query
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- How can I re-query post_type and rewrite the url?
- Finding post ID dynamically on click
- Ajax buttons not working properly in WooCommerce when using wc_get_template_part
- Load WP Query with Ajax
- Pre get posts sort by meta key returns no results if meta key does not exist
- Pre_get_posts only show posts by administrator roles
- Modify a query with no results in pre_get_posts
- How order by works?
- Woocomerce – Order products by float attribute in archive pages
- Order posts by title and custom field value?
- Custom Order Current Query: By Meta Key and Category
- remove_action – pre_get_posts – does not restore original query
- Limit default Search query to post_title
- Order & Orderby clause not working with custom query
- Is instantiating WP_Query not possible within an admin Ajax call?
- WordPress conflict with multiple load more posts functions on click
- why doesn’t this pre_get_posts code work?
- WordPress custom query by archive title
- pre_get_posts with WP_Query to prevent posts from specific tags
- Show All with Isotope
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- modifying the loop multiple times with arguments passed through ajax to wp_query
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Modify query to exclude certain ids and certain parents and its corresponding children
- Fetching $_POST from Page Template into functions.php
- WP_Query for liked posts is showing all posts if none are liked
- Declare inline background image in functions.php
- How to get query results for the next page
- How to solve this script problem in theme directory?
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- WordPress WP_Query offset parameter not working with search parameter
- Why is $wp_query fetching nothing?
- Adding a Theme Customizer Control for Posts_Per_Page
- wp_query – Modify $query to include duplicate content
- Order posts by custom column using pre_get_posts
- pre_get_posts or $where, which one to use?
- Inline Ajax call after term is appended with a @ or # etc. displayed in div
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Fire query on ajax post url page
- Sorting Posts Based On Meta Value Using AJAX
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- How return normal search result using wp_ajax action for wordpress
- Looking for a way to exclude frontpage and nav menu from query filter
- pre_get_posts redirecting
- Avoiding page loop
- Custom post types loop on a page template
- Duplicate posts showing up in loop using infinite scroll
- Adding arguments to WooCommerce Product Loop using AJAX
- Pre_get_post on CPT archive page
- Refresh wp_query with no changes
- WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function
- Search query alteration not working for meta values
- AJAX search function resets wp_query vars
- WordPress Ajax search filter on dropdown select
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- AJAX multiple search boxes not merging with array merge
- When to use WP_query(), query_posts() and pre_get_posts
- Applying a custom query for the AJAX “us_ajax_grid” function (from WPBakery)
- Optimizing AJAX Query with Large Database
- WP_query with ajax filter not working with input fields
- How to choose between hooking into pre_get_posts or into parse_query
- WP_Query offset returning duplicate posts from previous loops with AJAX