Search product by brand name in wp_query

Founded: $filter_group_a = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => 18, ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => 25, ), ); $filter_group_b = array( array( ‘taxonomy’ => ‘product_brand’, ‘field’ => ‘description’, ‘value’ => $tmp, ), ); $args = array( ‘post_type’ => ‘product’, ‘s’ => $tmp, ‘posts_per_page’ … Read more

Retrieve or Query Pages by ID

This is an inappropriate use of query_posts() which is only for modifying the main query for the page. Additionally, even if you change your snippet to use get_posts(), your template tags (e.g. the_excerpt()) won’t work as get_posts() isn’t a method of looping through posts, it just returns an array of posts. What you want is … Read more

List the 5 most recent child pages

Assuming you know (or know how to get) the $id (as an integer) of the parent post, use the post_parent parameter: $albums = new WP_Query(array( ‘post_type’ => ‘gallery’, ‘posts_per_page’ => 6, ‘post_parent’ => $id )); Edit Based on this comment: I don’t know the parent post. I want to list the most recent child pages … Read more

Understanding the use of wp_reset_query();

When you call query_post it replaces the main query object with one of its own, but that isn’t desirable. If you want to return to the main query, you have to call wp_reset_query to do so whichr estores the original query. I’d advise strongly against the use of query_posts and instead suggest you use WP_Query. … Read more

WP_Query or get_posts?

get_posts() simply uses a WPQuery object and sets a few default values. In general the values it sets make it mildly more performant. But I wouldn’t worry to much about it. get_posts() is simplier so as a rule of thumb if you don’t need any of the more involved features of WP_Query (including pagination) – … Read more

Filter WordPress posts by between parameter

Tax Query Limits A Taxonomy Query in WordPress supports the following three arguments for the operator parameter: IN, NOT IN and AND. So it basically can’t do what you’re trying to do. Not even with advanced (tax_query) Queries. Meta Query and possibilities You’ll want to move your concept a bit and work with post meta … Read more