Skip to content

Instantly share code, notes, and snippets.

@setola
Last active August 29, 2015 14:15
Show Gist options
  • Save setola/05d63243e8bee0dbec41 to your computer and use it in GitHub Desktop.
Save setola/05d63243e8bee0dbec41 to your computer and use it in GitHub Desktop.
WordPress invert post dates
<?php
$articles = get_posts(array(
'post_type' => MY_CUSTOM_POST_TYPE,
'numberposts' => -1
));
$date = array();
foreach($articles as $art){
$date[] = array($art->post_date_gmt, $art->post_date);
}
$date_r = array_reverse($date);
foreach($articles as $k => $art){
//echo 'from: '.$art->post_date.' to: '.$date_r[$k][1].'<br>'; // just to be shure
$art->post_date = $date_r[$k][1];
$art->post_date_gmt = $date_r[$k][0];
//wp_update_post($art); // enable this when you're sure :)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment