Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display the latest post from a "featured" category (id=1) that may also be in either X category, Y category, or Z category (id=2,3,4 respectively). Note, there are other posts in categories (A,B) that may also be listed under "featured" but I want to limit my results to the XYZ set.

Is there any special loop I can use to achieve this, or do I need to run a SQL query?

Also important to know that these are all top-level categories, so no child or parent cats to look through.

share|improve this question

migrated from stackoverflow.com Sep 20 '11 at 12:54

This question came from our site for professional and enthusiast programmers.

2 Answers 2

Maybe this could help and should return any post either in 2, 3 or 4 category AND in categoery 1 :

query_posts( array( 'cat' => array(2,3,4), 'category__and' => 1, 'posts_per_page' => 1, 'orderby' => 'title', 'order' => 'DESC' ) );

(from codex http://codex.wordpress.org/Function_Reference/query_posts)

Not quite sure, haven't tested it.

share|improve this answer

how about?

<?php 
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('cat=1,2,3,4&showposts=5');

if ( have_posts() ) while ( have_posts() ) : the_post();
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  <div class="entry-content">
    <span class="blog-date"><?php the_time(' M  jS, Y') ?></span>
      <h2 class="blog-post-title">
        <?php the_title(); ?>
      </h2>
      <?php the_content(); ?>
  </div><!-- .entry-content -->
</div><!-- #post-## -->
<?php endwhile; ?>
<?php 
 $wp_query = null; 
 $wp_query = $temp; 
?>

really just a custom query, which you can still filter to show number of posts etc..

share|improve this answer
    
This does not limit posts the way I need. In your code, posts that haven't been put in Featured but are in X,Y,or Z can still appear. I need to limit posts from those latter categories to only display IF they are also in Featured. –  f8xmulder Sep 20 '11 at 16:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.