I would like to be able to retrieve a post in a category based on if it has a certain tag.
Or in other words, I would like my loop to return the latest post from a certain category BUT if it has a tag of 'featured' then it would return the latest post with that tag first.
If the post does not have the tag 'featured' associated, then it would return the next latest post from that category without the tag 'featured'.
Maybe, ideally, the post could have a custom field for 'featured'?
I am using this code but not getting the results I want. Anyone have suggestions?
<?php
if (is_category(10) || is_tag('featured')) {
$featurednews = new WP_Query( 'tag=featured&cat=10&posts_per_page=1&orderby=date' );
};
else (is_category(10) {
$featurednews = new WP_Query( 'cat=10&posts_per_page=1&orderby=date' );
}
while ( $featurednews->have_posts() )
{
$featurednews->the_post(); // fill $post with data
?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="home-thumbnail">
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(160,160))?></a>
</div>
<div class="text">
<h2>latest news: <?php the_date('F j, Y');?>
</h2>
<h3><?php the_title() ?></h3>
<?php the_excerpt() ?>
</div>
</div>
<?php
}
rewind_posts();
?>