If we have the query arguments like this
$args = array(
'queryid' => 'blackjack',
...
);
$q = new WP_Query( $args );
Note we added one custom query argument that is not officially present in here.
Now we can identify the exact query by that queryid
if we use the second parameter of the posts_where
hook.
function f_posts_where( $where, \WP_Query $q ){
// $q->query will hold the query arguments ...
if ( 'blackjack' == $q->query['queryid'] ){
// do our custom actions on $where for our queryid blackjack
return $where.
}
return $where;
}
add_filter( 'posts_where', 'f_posts_where', 10 , 2 );
As you can note $q->query
will hold the query arguments.
This will allow us to intercept the custom queries we like if we add custom arguments we like. In this case the queryid
.
Related Posts:
- return child post if available otherwise parent post
- Search has query that will return no results
- Is my code correct?
- How to make a search query if not found in post table then search in postmeta table?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- WP Query – Search in title or author_name
- URL to Post Archive of Custom Query
- Query by meta value (add a dropdown of all values)
- Meta query doesn’t remove placeholder escape before query
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- How to show post title in content editor in backend?
- How to show terms from another taxonomy
- Adding Category in WP_Query Not Working
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- What is the best way to reset a search on a meta_key / meta_value?
- Ignoring ‘a’ when sorting posts
- how to show more than 1 post into three columns query
- How can I modify standard search query to include also ACF custom fields values?
- Using the same WP_Query for shop and widgets in WooCommerce shop
- How can I get all the posts that are related with a specific taxonomy term?
- Fetch only categorized posts
- Bring a post to the top of the query if it’s in a certain category?
- orderby in WP_QUERY – Use the order from the Dashboard
- Random posts in WP_Query when searching by tag
- WP_Query with child element
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- Custom pagination (Title, date and teaser)
- Using URL variables on a custom WP_Query
- Ordering Posts by parent category, name ascending
- Query posts in current category but not attachment format
- Filter posts/pages by user_role array
- WP_Query always returning the last custom post
- WP_Query secondary query failing
- How to get query results for the next page
- Search Functionality broken by the wp 4.2 update
- Issue attempting a wp_query_posts with tags
- How to query post into a complex slider
- wp_query – Modify $query to include duplicate content
- Using WP_Query to re-query and sort results using a date?
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- Pagination is not working on custom query inside a custom home page template
- Loop through multiple custom fields with increasing number
- Combine privileged users array with my current query
- Pagination in custom query in a category page
- Horizontally paginate through sets of blog posts?
- How to organize a WP_Query’s list of posts by category and display category title?
- Get a list of the last posts grouped by author and filtered by category
- add_query_vars does not work
- Need help setting up a search form for wordpress [duplicate]
- Pagination not working with WP_Query (creates links but no page)
- When should you use WP_Query vs query_posts() vs get_posts()?
- Query custom post type by date field only working when two posts match the query
- meta_query dates from an array
- Divide WP_Query posts by date & post type
- Retrieve posts in custom post type and specific taxonomies
- How to query post ids liked by the Author
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- query by meta value then date and not empty meta value
- confirm my booking with phone number
- New WordPress WP Query using posts from certain categories
- Modify query after meta value
- Custom post types loop on a page template
- Get WP_Query query after execution?
- Showing posts from 4 categories along with all latest posts
- Get the number of rows from $wpdb->get_results not working
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- Pagination in WP query with transient API
- Parsing External Table Arguments
- Get Child Custom Post Content on Single.php?
- difference between methods of query
- Query posts by meta value and sort by another meta key
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Pre_get_post on CPT archive page
- Get posts that were most recently tagged
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- wp_query order by rand is repeating posts
- A Depth Like Parameter For “get_posts”
- Use meta query only 3 or more results?
- Search query alteration not working for meta values
- Search results stuck on page 1
- Advanced Search – Is this possible?
- Use value from meta key array for use in WP_Query
- How to get posts that have certain meta key value and order based on another meta key’s value
- Filtering custom post type list in admin by custom meta key/value
- How to use meta_query to retrieve posts from multiple custom post type
- Modify WordPress Search
- Block Editor – WordPress 6.1 – CPT Archive Issue – While the title changes in the loop, all records display the same data
- $wp_query->found_posts; returns zero
- Rewrite URL custom search query
- Multiple queries and pagination
- posts_per_page showing 16 elements instead of 3