The most reliable way is to define your own query var and then check it:
$my_query = new WP_Query( array(
...
'context' => 'my_query'
) );
Then, from your callback:
function alter_post_clauses( $clauses, $wp_query ) {
if ( 'my_query' == $wp_query->get( 'context' ) ) {
// do stuff
}
return $clauses;
}
add_filter( 'posts_clauses', 'alter_post_clauses', 10, 2 );
Related Posts:
- Exclude a category from WP_Query
- Single loop for wp_query and wp_user_query
- WP_Query orderby custom field then post_date in one query
- query multiple taxonomies
- Include post id[s] into WP_Query()
- Syntax to get the Nth item in a list of custom post types?
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Pagination Doesn’t Work
- Using Query Posts With Multiple Post Types And A Taxonomy
- List with categories, subcategories and posts of custom posttype
- Sort the main query in subcategories/terms?
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- Custom Taxonomy List links being re-written
- Can’t sort order of wp_query with 2 meta keys
- Get post info inside modal window?
- Want to filter only parent post in admin area
- Get count of custom post type created by current user
- Query Custom Post by Category
- Pagination Issue: Custom Post Type In Index
- Having trouble with custom date field for CPT query (WordPress)
- Display posts if a custom field value is equal to another custom field value
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Custom post query by taxonomy
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to use WP_Query in a CPT achive page?
- Use get_post_types to query only custom posts types
- Group custom posts by custom taxonomy names
- How can i skip same post from taxonomy term?
- Using global $post; to get featured image for custom post via WP_Query
- Can’t query tag and post_type at the same time
- Pagination on a custom post type loop
- WP_Query orderby modified to include custom meta changes
- Wrong request query on cpt and tax
- Converting the_content string to an array?
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- What’s the WP way to load remaining custom posts?
- Filter Posts from the Main Query
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()
- Multiple Custom Post Type queries, how to DRY it up
- Custom WP_Query always respond with 200 status even when no entry
- post_per_page ignored in WP_Query
- Pagination 404 on Index with custom query
- WP_Query parameter conflict
- Retrieving meta-box from a custom-post-type
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Custom post type and standard post not displaying or working
- Get all post from a post type
- Trying to add a class to post links
- A faster way to query custom post types with multiple conditions?
- Custom Post Type Archive Pagination
- List all Custom Post Type posts excluding certain Taxnomy term
- Two queries – one with checkbox ticked, one without – comparing meta_query
- Custom post type pagination error
- WP query_posts group by meta field related
- posts_per_page in custom WP_Query does not override “Reading” settings?
- Display Parent-Child Posts in specific order by comparing IDs in array
- Apply category query clause to posts of custom type
- custom post type and a “sticky” position taxonomy
- Display post count for a specific month
- Query to Exclude Child Pages from Custom Post Type Archive
- WP_query has incorrect wp_posts.post_name = ‘asc’ when I have custom post type called ‘order’
- Randomizing WordPress Custom Post Type Sorting Through Them Without Page Refresh
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to output custom post type title on custom page with category next to it?
- SEARCH QUERIES – REVERSE OUTPUT
- WP_Query to display number of custom post type filtered (order by) taxonomy
- 2 modal windows with ACF content on Archive page
- post_type incorrect for custom post type
- Live search by custom tag
- Custom Post Type – Display all, wrap in groups of 3
- Staggering featured post using ‘sticky’
- Ajax load more inside custom post type taxonomy
- How to get the posts that my following users are liked?
- Only show categories that have posts within custom post type
- Create a custom wp_query from a specific custom post type with specific taxonomy
- How can you use a page for a custom post type?
- Display all Custom taxonomy terms and their relevant custom posts
- Query breaking with ‘posts_per_page’ => -1
- WP Query with multiple post types ordered by custom meta date then published date
- CPT Efficient way to display posts from different categories with custom query
- How To Loop Through list with Custom Post Types
- CPT or Custom Table for Repository of Serial Numbers
- Query Pulling the same post twice
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- Custom Post Type + Category archive
- WP_Query get posts where post_name is empty
- How do I sort post listing by child post count?
- Pop up showing same content on all posts display.
- Custom post-type’s pagination not working in category.php
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Querying meta values within an array
- Count of posts with meta_key filled in?
- Filter Custom post type by another Custom post type
- Archive page – problem with pagination
- Are custom posts included when getting a categories’ posts?
- Query order by meta value force specific tag first
- Can I add a wordpress page using the slug for a CPT rewrite
- Assign a tag to custom post type using a query
- Query order by a numeric ACF field