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:
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- ajax category filter
- Slow SQL_CALC_FOUND_ROWS Query
- Ajax and WP_Query/tax_query parameter
- SQL Statement generated by WP_Query not producing expected results
- get data from wp-query, outside the loop & without url change
- Sorting Posts by custom field
- Recommended way to drop a pending query (in pre_get_posts)?
- Ajax Infinite Scroll In Custom WP_Query Loop Not Working
- WP_Query class not found
- Search – Ajax – Alter Query Parameters with Pagination
- 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?
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How to Modify Taxonomy Archive Page with Search Parameter?
- WP_Query orderby breaks when using AJAX?
- How to display future posts – modified query still yields 404
- Including only current user’s posts in search
- Refine/Filter WP_Query Posts with jQuery or Ajax
- Create unique page without header.php for json feed
- WP_Query ajax loader detect end of posts
- 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
- Store sticky post’s ids in a transient
- Ajax Pagination on Ajax filter
- Wp_query returning only one post while query through ajax
- Show Sticky Post at the top but do not show again in the loop?
- Ajax load more posts – WP_Query parameters not working
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Show scheduled posts in main loop but not in WP_Query?
- 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
- Order ascending is ignored in meta query?
- 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
- 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?
- 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
- Refresh wp_query with no changes
- 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`