WordPress get_posts() post limit

I am using wordpress’s function the_excerpt(). It works fine, but in the result is only shows 5 of my post’s. How can I make it display all posts instead of only the 5 most recent?

My code:

<?php

    $lastposts = get_posts();

    foreach ( $lastposts as $post ) :

            setup_postdata( $post ); ?> 

            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

            <p style="font-size:12;"><em>Post date: <?php the_date(); ?></em></p>

            <?php the_excerpt() ?>

            <a href="<?php echo get_permalink(); ?>"> Read more...</a>

            wp_reset_postdata();

    php endforeach; ?>

Related posts

Leave a Reply

1 comment

  1. Your problem is not with the_excerpt() but rather with get_posts(), since that is the array your loop is iterating over.

    Try:

    <?php
    
    $lastposts = get_posts(array('posts_per_page' => -1));
    
    foreach ( $lastposts as $post ) :
    ...