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>

1 Answer 1


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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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