user10042804
user10042804

Reputation: 7

php only loops 5 times, should loop for each post

i am not skilled in php, so maybe i am overlooking something simple/stupid.

But the following code only seems to loop 5 times (atleast it only outputs 5 sites) While this specific category has 12 sites in it for example.

Am i doing something wrong?

<div class="col-md-3">
<div class="maddos-category-container">
<div class="maddos-category-header"><h3 class="maddos-category-header-title"><a href="<?php echo get_category_link( "17" );?>"><?php echo get_cat_name(17);?></a></h3></div>
<div class="maddos-category-wrapper">
<ol>
   <?php
    $args = array( 'category' => 17, 'post_type' =>  'post' ); 
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?>  
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
    <?php endforeach; ?> </div></div></div>
</ol>

Upvotes: 0

Views: 92

Answers (1)

Felippe Duarte
Felippe Duarte

Reputation: 15131

Take a look at the docs for get_posts

$args

(array) (Optional) Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments.

'numberposts' (int) Total number of posts to retrieve. Is an alias of $posts_per_page in WP_Query. Accepts -1 for all. Default 5.

So, replace:

$args = array( 'category' => 17, 'post_type' =>  'post' ); 

With

$args = array( 'category' => 17, 'post_type' =>  'post',  'numberposts' => -1);  //unlimited

Upvotes: 2

Related Questions