Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wp_query example for meta query with multiple meta field.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
/*'meta_key' => 'ingredients',
'meta_value' => ' ',
'meta_compare' => '!='*/
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'ingredients',
'value' => ' ',
'compare' => '!='
),
array(
'key' => 'custom_product_type',
'value' => 'recipe',
'compare' => '='
)
)
);
$the_query = new WP_Query( $args );
$count = $the_query->post_count;
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment