0

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> 
1
  • die(count($postslist)) or var_dump($postslist) would be a good place to start. What does the declaration for get_posts function look like? My guess is one of the arguments is $limit = 5. Commented Jul 9, 2018 at 21:17

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

I had to wait a few more seconds to accept the answer, but done now :) also learned something new, so also thank you for that!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.