Created
September 27, 2018 07:56
-
-
Save navnit-viradiya/b85e60392672ee1661d23fd41f68d972 to your computer and use it in GitHub Desktop.
Wp_query example for meta query with multiple meta field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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