Search code examples
wordpress

get_posts not returning all posts


I have to mount the blog posts manually, but I'm not sure if this is the correct way to work, It only brings 9 pages, with 4 posts each, but the blog has 83 posts!

<?php
    $paged = get_query_var('paged');
    $args = array(
        'numberposts'       => 4,
        'offset'            => $paged*4,
        'orderby'           => 'post_date',
        'order'             => 'DESC',
        'post_type'         => 'post',
        'post_status'       => 'publish',
        'suppress_filters'  => true
    );
    $posts_array = get_posts( $args );
?>

Thanks anyway.


Solution

  • Problem is your 'numberposts' is set to 4 Put it at -1 to get all posts:

     'numberposts'       => -1,
    

    If you don't set numberposts here, WordPress will default to 5 (Codex)