• Resolved rbryant4

    (@rbryant4)


    Hey everyone–having a slight issue: my WP_Query() function is only returning 10 pages and/or posts even though there are many more. I can’t figure it out!

    $my_wp_query = new WP_Query();
    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page');
    for ($r = 0; $r < count($all_wp_pages); $r++){
    echo ' <!--'. print_r($all_wp_pages[$r])  .'-->';
    }

    Here’s a snippet of code where I’m getting the issue–It’s only returning the 10 LATEST posts or pages made. If I make a new ‘page’ then it will be returned at the top of the returned list, but the oldest one in the list will get pushed out and not be in the list anymore. I’m super confused why this is happening.

    Thanks guys!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter rbryant4

    (@rbryant4)

    To illustrate:

    I have 9 example pages that WP_Query returns on ‘post_type’ => ‘page’

    CURRENT
    Site Pages
    (9) pages total
    ——-
    Page 9
    Page 8
    Page…
    Page 2
    Page 1
    END LIST

    AFTER ADDING
    one new page
    (10) pages total
    ——-
    START RETURNED LIST
    Page 10
    Page 9
    Page…
    Page 2
    Page 1
    END LIST

    AFTER ADDING
    2 new pages
    (11)
    ——-
    START RETURNED LIST
    Page 11
    Page 10
    Page…
    Page 3
    Page 2
    END LIST

    Thread Starter rbryant4

    (@rbryant4)

    I figured it out-FINALLY. Apparently I needed to add:

    ‘posts_per_page’=> -1

    to my WP_Query() arg list. The default–which I still don’t know where it’s set–was apparently 10. This overrides it.

    Everything is working again!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP_Query only returns 10 items’ is closed to new replies.