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

I'm a noob at this so please bear with me.

I have the following code to return post title as links within categoryID 6, which is working fine:

<?php global $post; $cat_posts = get_posts('numberposts=10&category=6');
  foreach($cat_posts as $post) : ?>
    <?php $postTitle = get_the_title(); if($title != $postTitle) :?>
    <li><a href="<?php the_permalink(); ?>">&rsaquo;&rsaquo; <?php the_title(); ?></a></li>
    <?php endif ;?>
<?php endforeach; ?>

However, the category ID is a variable, e.g. $catID, can I use this in the above code?

Thanks in advance!

share|improve this question
up vote 3 down vote accepted

Have you tried the following code?

$cat_posts = get_posts('numberposts=10&category='.$catID);
share|improve this answer
That worked a treat - thanks Lea! – user3907 Mar 13 '11 at 9:44

Your Answer


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