Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Created September 24, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivertappin/777430abda2fa6821d8a402934efc62d to your computer and use it in GitHub Desktop.
Save olivertappin/777430abda2fa6821d8a402934efc62d to your computer and use it in GitHub Desktop.
Loop over WordPress posts using PHP
<?php
require_once '../../../../wp-load.php';
$page = 0;
do {
$news = get_posts( [
'posts_per_page' => 50,
'paged' => $page
] );
foreach( $news as $article ) {
echo 'Updated article with ID: ' . $article->ID . PHP_EOL;
}
$page++;
} while (count($news) > 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment