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
I can give a generic example, but it would be highly dependent on how you are displaying date/time values and this code may not work.
add_filter('acf/load_value/name=repeater_field_name', '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 timestamp
$now = time();
// 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 = strtotime($row['start_date']);
$end = strtotime($row['end_date']);
if ($start > $now || $end > $now) {
$new_value[] = $row;
}
}
return $new_value;
}
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.