Meta Query relation “AND” not working

You mixed meta query and tax query It should look like this $query = array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 12, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ) ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_visibility’, ‘field’ => ‘name’, ‘terms’ => ‘featured’ … Read more

Add condition of user capability in WP_query

#SOLVED# Issue is solved by defining the meta_query conditions with an if statement. So if current_user_can(‘subscriber’) the meta_query includes the conditions, otherwise the query includes all posts. This is the code in case this is helpful for anyone else: <?php //create variables $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; … Read more

How to use WP_Query without breaking the main Query

it’s unclear when to use one or the other, or if they must be used at all If you’ve modified the global $wp_query variable (e.g. using query_posts() which should NOT actually be used), then use wp_reset_query() to restore the variable back to the main query, i.e. so that the variable references or points to the … Read more

Pagination of a WP_Query Loop in a child-page page template

Glad that you managed to figure out a solution, which yes, does work. But you could make it more selectively, i.e. target just the specific pages, by using is_single( ‘<parent slug>/<child slug>’ ), e.g. is_single( ‘family-law/success-stories’ ) in your case. Secondly, it’s not exactly the redirect_canonical hook which caused the (301) redirect on singular paginated … Read more

Query with a meta value inside a given range

In this situation you will want to use the meta_query parameter, an example: $args = array( ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => $key, ‘value’ => array($min, $max), ‘compare’ => ‘BETWEEN’, ), ), ); $query = new WP_Query( $args ); The possible values for for the ‘compare’ key are: “=” … Read more