Skip to content

Instantly share code, notes, and snippets.

@jim912
Last active August 29, 2015 13:56
Show Gist options
  • Save jim912/9268779 to your computer and use it in GitHub Desktop.
Save jim912/9268779 to your computer and use it in GitHub Desktop.
予約投稿が失敗した記事を強制的に公開するスクリプト。cron なんかで叩くべし
<?php
echo '======= Start script ' . date( 'Y-m-d H:i:s' ) . ' ======' . "\n";
require_once( dirname( __FILE__ ) . '/path-to/wp-load.php' );
$current_time = current_time( 'mysql' );
$published_ids = array();
$sql = "
SELECT ID
FROM $wpdb->posts
WHERE post_status = 'future'
AND post_date < '$current_time'
";
$post_ids = $wpdb->get_col( $sql );
if ( $post_ids ) {
echo count( $post_ids ) . ' future posts found.' . "\n";
foreach ( $post_ids as $post_id ) {
$ret = wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) );
if ( $ret ) {
$published_ids[] = $post_id;
}
}
echo count( $published_ids ) . '( ' . implode( ', ', $published_ids ) . ' ) posts published.' . "\n";
} else {
echo 'no future posts found.' . "\n";
}
echo '========= End script ' . current_time( 'mysql' ) . ' ======' . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment