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
- Reduce or prevent calling of update_meta_cache
- Order Search Results Page by meta_value If no Value Return Remaining Results
- How-to exclude terms from the main query the most performant way?
- Slow SQL_CALC_FOUND_ROWS Query
- RSS feed with specific keyword
- Ajax and WP_Query/tax_query parameter
- get data from wp-query, outside the loop & without url change
- Sorting Posts by custom field
- Query with pre_get_posts to get pagination
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- How to sort posts in admin by titles with dd.mm.yyyy format?
- WP_Tax_Query with post_tag not working
- How to Modify Taxonomy Archive Page with Search Parameter?
- WP_Query orderby breaks when using AJAX?
- WP_Query & AJAX
- Sticky Post default functionality with WP_Query is ignored when using AJAX
- pre_get_posts filter meta_query without conflicting existing meta_query
- Including only current user’s posts in search
- How to change posts order on Category and Tag archives?
- Create unique page without header.php for json feed
- My Main Query Modification is Messing up my dynamic main – why?
- wp_query not searching with apostrophe
- pre_get_posts Remove tax_query Completely
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Include custom field in Ajax search WordPress
- Show Sticky Post at the top but do not show again in the loop?
- Ajax load more posts – WP_Query parameters not working
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Load More Posts Button – AJAX
- hide custom post types with specific meta key ON admin backend
- WP_Query ignoring tax_query when is_singular
- Applying posts_clauses filter to specific queries only
- Help ordering Post loop by two meta values
- New WP_Query calls Pre_get_posts filter twice
- Current post in AJAX call is always zero
- Filter wordpress post categories with jquery/ajax and pagination?
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- how update data through ajax and jquery
- pre_get_posts – Trying to get property of non-object warning
- Error with function in functions.php?
- Use Ajax To filter posts?
- queried_object using pre_get_posts gets notices and warning
- date_query in pre_get_posts out of memory
- Loading two different AJAX requests on two different pages
- AJAX Breaking Offset Argument In WP Query
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- Multiple meta_key ordering with pre_get_posts
- WP_Query offset is returning post from prevois loop
- Sorting search results with custom dropdown
- pre_get_posts – editing query, tax_query
- Does WP_Query ‘responds’ badly to empty arguments?
- Child pages not affected by orderby
- ajax wp_query conditional tags not working
- Change post query onclick
- How to apply pre_get_posts to a custom query?
- How to pass the current content of $wp_query to a new page?
- WP_Query, Paginate by Custom Field
- JOIN filter doesn’t work in WP_Query in wp-ajax calls
- 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
- 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_user_query vs pre_get_posts
- Can I alter the main loop to ‘orderby’ a custom callback?
- WordPress live search and filter custom fields
- WordPress live search and filter
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- How can I re-query post_type and rewrite the url?
- Finding post ID dynamically on click
- 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
- How order by works?
- Custom Order Current Query: By Meta Key and Category
- remove_action – pre_get_posts – does not restore original query
- WordPress custom query by archive title
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Modify query to exclude certain ids and certain parents and its corresponding children
- Fetching $_POST from Page Template into functions.php
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- wp_query – Modify $query to include duplicate content
- 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)?
- 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
- Avoiding page loop
- Custom post types loop on a page template
- Pre_get_post on CPT archive page
- WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function
- AJAX search function resets wp_query vars
- WordPress Ajax search filter on dropdown select