Skip to content

Instantly share code, notes, and snippets.

@Tusko
Created October 24, 2018 11:21
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 Tusko/60ba7a3e13b24489c458e7e0c16e69b9 to your computer and use it in GitHub Desktop.
Save Tusko/60ba7a3e13b24489c458e7e0c16e69b9 to your computer and use it in GitHub Desktop.
Set random dates for events ACF/WP
<?php
$allevents = wp_get_recent_posts(array(
'showposts' => '-1',
'post_type' => 'events'
));
$start = strtotime("10 October 2018");
//End point of our date range.
$end = strtotime("22 November 2020");
foreach ($allevents as $ev) {
$timestamp = mt_rand($start, $end);
$randomDate = date("Y/m/d", $timestamp);
update_field('field_5bd04e09e2fdc', $randomDate, $ev['ID']);
var_dump($randomDate, get_field('start_date', $ev['ID']));
echo '<br>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment