Skip to content

Instantly share code, notes, and snippets.

@orangerdev
Created October 13, 2017 07:14
Show Gist options
  • Save orangerdev/8982dde81c09553d76a2258fdde0c3de to your computer and use it in GitHub Desktop.
Save orangerdev/8982dde81c09553d76a2258fdde0c3de to your computer and use it in GitHub Desktop.
Chunk WP_Query to get all posts
<?php
$found_posts = true; // Set as true
$offset = 0; // Set start post
$posts_per_page = 20; // Chunk for each 20 posts
while($found_posts) :
$query = new WP_Query([
'posts_per_page' => $posts_per_page,
'offset' => $offset
]);
if($query->have_posts()) :
// DO WHAT?
else :
$found_posts = false;
endif;
endwhile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment