WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

got myself in a bit of a pickle. I want to display posts on category.php from the categories 'latest news' and 'custom models' only. The other category, 'press releases' is shown in a separate column.

I've the following code - hashed together from misc articles I've read - but it's showing ALL the posts rather than just my 2 chosen categories.

Perhaps the easiest way would be to show all posts apart from 'press releases'...

Can anyone help?

  <div id="rightColumn">
      <?php single_cat_title() ?>
    <?php $posts = get_posts('category=Latest News,Custom Models'); foreach($posts as $post) { ?>
    <div class="newsListing">
      <div class="imageContainer"><a href="<?php the_permalink(); ?>">
// Must be inside a loop.

if ( has_post_thumbnail() ) {
else {
    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/shared/placeholder.jpg" />';
      <h2><a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        <?php the_time('F jS, Y') ?>
      <?php the_excerpt(); ?>
      <p class="readMore"><a href="<?php the_permalink(); ?>">Read more</a></p>
      <div class="clearBoth"></div>
    <?php } ?>
    <div class="clearBoth"></div>
    <div id="nav-below" class="navigation">
      <p class="floatRight">
        <?php posts_nav_link('','&lt; Recent entries','Older entries &gt;'); ?>
      <div class="clearBoth"></div>
share|improve this question
up vote 1 down vote accepted

Function get_posts accepts comma separated categories' ids or slugs, not names. As it makes use of WP_Query, see Category Parameters.

share|improve this answer
So code will change to this... <?php $posts = get_posts('category_name=latest-news,custom-models'); foreach($posts as $post) { ?> – V Neal Dec 14 '12 at 10:40
Yes, that's right. – Max Yudin Dec 14 '12 at 10:57

Your Answer


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.