Forked from desrosj/Getting all posts without a no LIMIT query
Created
November 27, 2018 04:56
-
-
Save palaa159/d2cf5afe1ef777b1d300761c412bdd68 to your computer and use it in GitHub Desktop.
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 | |
$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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment