get_posts arguments (4 posts)

  1. jimHere
    Posted 9 years ago #

    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?

    $posts = get_posts('numberposts=25');
    foreach($posts as $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>
    <?php endforeach; ?>

  2. jimHere
    Posted 9 years ago #

    Is it the "foreach" thing?

  3. Kafkaesqui

    Posted 9 years ago #

    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?).

  4. jimHere
    Posted 9 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic