Created
November 27, 2012 04:19
-
-
Save caratage/4152345 to your computer and use it in GitHub Desktop.
query_posts exclude by meta key
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
// Set up a custom query | |
$featured_query = new WP_query(); | |
// Your query args | |
$featured_args=array( | |
'post_type'=>'post', | |
'meta_key'=>'featured_product', | |
'meta_value'=>'1' | |
); | |
// Run it | |
$featured_query->query($featured_args); | |
if ($featured_query->have_posts()) { | |
while ($featured_query->have_posts()) { | |
$featured_query->the_post(); | |
// Remember the featued ID | |
$featured_post_id = get_the_ID(); | |
// Render your featured post here | |
} | |
} | |
// Set up the args for your main query | |
$args = array( | |
'post_type' => 'post', | |
'post__not_in' => array($featured_post_id) // Don't show the featured post | |
); | |
// Now run your main query and so on... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment