Created
October 13, 2017 07:14
-
-
Save orangerdev/8982dde81c09553d76a2258fdde0c3de to your computer and use it in GitHub Desktop.
Chunk WP_Query to get all posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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