Created
November 2, 2011 22:12
-
-
Save mjangda/1335091 to your computer and use it in GitHub Desktop.
Simple generic command line script for WordPress
This file contains 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 | |
// Let's load WordPress | |
require( 'wp-load.php' ); | |
if ( ! function_exists( 'wp' ) ) | |
die( 'Sorry, looks like WordPress isn\'t loaded.' ); | |
// Run the core code for our script | |
my_command_line_script(); | |
function my_command_line_script() { | |
// We're going to run through batches of 50 posts at a time | |
$posts_per_page = 50; | |
// Set up the main query args | |
$args = array( | |
'posts_per_page' => $posts_per_page, | |
'offset' => 0, | |
); | |
// Let's get our first batch | |
$query = new WP_Query( $args ); | |
// Now let's loop through out posts until we've gone through all of them | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
// Our main script actions would go here... | |
// Let's get the next batch | |
$args['offset'] += $posts_per_page; | |
$query = new WP_Query( $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello,
how can I execute this script via command line ?