lbar
lbar

Reputation: 21

Strange behaviours getting all post from wordpress category

today i need to get all the posts from a specific category on wordpress.

The code it's pretty basic, and it's like that:

print_r(get_posts(array('numberposts' => -1, 'category' => 3)));

The id of the category it's obviously 3. But i receive always the last 5 posts of that category, not all the post present there (something like 60posts).

Anyone know why could happen this strange stuff?

Upvotes: 1

Views: 49

Answers (1)

DLaverick
DLaverick

Reputation: 655

Try something like this:

<ul>
<?php


$args = array( 'numberposts' => -1,'category' => 3 );

 $myposts = get_posts( $args );
 foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;  wp_reset_postdata();?>

</ul>

If this works for you, all you need to do then is to change the output display(the ul and li)

Upvotes: 1

Related Questions