Is there an action/filter called when WP_Query->query is finished and assigns posts
The is the the_posts filter, which sounds like what you want. function filter_the_posts($posts) { var_dump($posts); } add_filter(‘the_posts’,’filter_the_posts’);
The is the the_posts filter, which sounds like what you want. function filter_the_posts($posts) { var_dump($posts); } add_filter(‘the_posts’,’filter_the_posts’);
The issue is that WordPress are getting all posts that has a ‘startDate’ meta key, no matter the meta value. You can understand that form this part of the request: … AND ( wp_postmeta.meta_key = ‘startDate’ OR ( mt1.meta_key = ‘startDate’ AND CAST(mt1.meta_value AS CHAR) >= ‘20140305’ ) OR ( mt2.meta_key = ‘endDate’ AND CAST(mt2.meta_value … Read more
The pre_user_query action hook in WordPress will allow you alter the SQL statements in the WP_User_Query object before they are run against the database. Note, this is an action, not a filter, so there’s no need to return the $user_query that gets passed in. add_action( ‘pre_user_query’, ‘add_my_custom_queries’ ); function add_my_custom_queries( $user_query ) { $user_query->query_fields .= … Read more
This is working for me on a single page using a template. Just be sure to set next_posts_link( ‘Older Entries »’, $the_query->max_num_pages );. // set the “paged” parameter (use ‘page’ if the query is on a static front page) $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : ‘1’; $args = array … Read more
According to http://v2.wp-api.org/reference/posts/ you have categories_exclude available as a param to pass to the API. This should work: http://localhost/wp-json/wp/v2/events/?categories=23&categories_exclude=42&per_page=1 …to get the posts from category 23, but exclude those that also have 42 assigned as category.
There should not be any need to do this. Even if an ACF Field is using ‘return_format’ => ‘m/d/Y g:i a’, The post_meta value is in YYYY-MM-DD 00:00:00 format. $date_now = date(‘Y-m-d’); $args = [ ‘meta_key’=>’the_date’, ‘meta_value’=>$date_now.’ 00:00:00′, ‘meta_compare’=>’>=’, ]; $query = new WP_Query( $args ); Edit: I’ve noticed some discrepancies in this, the value … Read more
You won’t be able to translate a complicated SQL query directly to a WP_Query. What you can do is return Post IDs from the SQL and pass those IDs into the WP_Query args. Do note that this is highly inefficient and will likely create slow queries as post__in is not fast. You need to modify … Read more
WP_Query is a PHP Class, class names are capitalized, with words separated by underscores, as per the Naming Conventions in WordPress Coding Standards.
As with most questions involving OR clauses, the answer is the same: use a custom query or alter WP_Query using the ‘posts_clauses’ filter.
(Untested) but should works with any taxonomy including the ‘tag’ taxonomy (post_tag). The following example uses the taxonomy with name ‘my-taxonomy’. <?php //Get terms for this taxonomy – orders by name ASC by default $terms = get_terms(‘my-taxonomy’); //Loop through each term foreach($terms as $term): //Query posts by term. $args = array( ‘orderby’ => ‘title’, //As … Read more