Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save desrosj/de6a3923c61f5b4a3046a643e286abab to your computer and use it in GitHub Desktop.

Select an option

Save desrosj/de6a3923c61f5b4a3046a643e286abab to your computer and use it in GitHub Desktop.

Revisions

  1. desrosj revised this gist May 24, 2016. No changes.
  2. desrosj created this gist May 24, 2016.
    18 changes: 18 additions & 0 deletions Getting all posts without a no LIMIT query
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php
    $posts = array();

    $args = array(
    'posts_per_page' => 100,
    'offset' => 0,
    'post_type' => 'post',
    'post_status' => 'publish',
    );

    $my_query = new WP_Query( $args );

    while ( $my_query->have_posts() ) {
    $posts = array_merge( $posts, $my_query->posts );

    $args['offset'] = $args['offset'] + $args['posts_per_page'];
    $my_query = new WP_Query( $args );
    }