Home › Forums › Front-end Issues › Delete ACF repeater field entry from backend after date expiry › Reply To: Delete ACF repeater field entry from backend after date expiry
add_filter('acf/load_value/name=start_date', 'delete_old_courses_by_date');
function delete_old_courses_by_date($rows, $post_id, $field) {
if (!is_array($value) || !count($value)) {
return $value;
}
// get the current date
$now = date("Ymd");
// set up a new array to hold the values we keep
$new_value = array();
foreach ($rows as $row) {
// the php strtotime() function could fail depending on
// the return format of the date/time fields
// this requires a valid date/time format as documented here
// http://php.net/manual/en/datetime.formats.php
// if this does not work I probably won't be much help figuring
// our how to covert your return value to something usable
$start = date("Ymd", strtotime(get_sub_field('start_date')));
if ($start > $now) {
$new_value[] = $row;
}
}
return $new_value;
}
Look at this code. Can you figure out what is wrong with it.
The fields look like this in admin
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.