Get posts only if custom fields match
-
I am trying to achieve this : I have 2 custom fields
product_size
product_colorIf I use
$args = array( 'meta_key' => 'product_size', 'meta_value' => 'S', 'post_type' => 'any' );
and if i use this
$myposts = get_posts($args);
I get all posts which have product_size as S.
Secondly if I do
$args = array( 'meta_key' => 'product_color', 'meta_value' => 'Blue', 'post_type' => 'any' );
and if i use this
$myposts = get_posts($args);
I am able to get all posts with product color Blue.
But when I use meta_query
I am not able to do a query like…
if product color = Blue and product size = S show posts…
Thats not working. It always returns 0 value even though I manually checked and have posts wherein product size is S and product color is Blue. What is the query to be used to do AND query where in both conditions need to be fulfilled. i.e product color and product size
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get posts only if custom fields match’ is closed to new replies.