Created
October 24, 2018 11:21
-
-
Save Tusko/60ba7a3e13b24489c458e7e0c16e69b9 to your computer and use it in GitHub Desktop.
Set random dates for events ACF/WP
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 | |
$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