• I’m trying to get WP to display infro from the_excerpt is a page, but I can’t make get_posts obey ‘category=5’ to make it only show posts from my “photos” category. It WILL work with ‘numberposts=25’, but not ‘category’, as described in http://codex.wordpress.org/Template_Tags/get_posts. Why?

    <?php
    $posts = get_posts('numberposts=25');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    <div id="post">
    <div class="thumb">
    <a href="<?php the_permalink(); ?>" title=""><?php the_excerpt(); ?></a>
    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <h4><?php the_time('M jS, Y') ?></h4>
    </div>
    </div>
    <?php endforeach; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jimhere

    (@jimhere)

    Is it the “foreach” thing?

    I can’t say for sure, but it’s *possible* a conflict with WordPress’ global $posts object is being exhibited here. Try changing your code to something like:

    $my_posts = get_posts('numberposts=25&category=5');
    foreach($my_posts as $post) :

    Note I added in the category argument, assuming you just left it off here (you were using it, correct?).

    Thread Starter jimhere

    (@jimhere)

    That totally worked — thanks.
    Was it a php syntax thing? I’m not that good with the deeper guts of WP…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_posts arguments’ is closed to new replies.