Skip to content

Instantly share code, notes, and snippets.

@navnit-viradiya
Created September 27, 2018 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navnit-viradiya/b85e60392672ee1661d23fd41f68d972 to your computer and use it in GitHub Desktop.
Save navnit-viradiya/b85e60392672ee1661d23fd41f68d972 to your computer and use it in GitHub Desktop.
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