Skip to content

Instantly share code, notes, and snippets.

@caratage
Created November 27, 2012 04:19
Show Gist options
  • Save caratage/4152345 to your computer and use it in GitHub Desktop.
Save caratage/4152345 to your computer and use it in GitHub Desktop.
query_posts exclude by meta key
// 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