Home › Forums › Backend Issues (wp-admin) › year picker › Reply To: year picker
I know this is a pretty old post, but if anyone else wanted the code to make this happen:
function sevenYearSelect($field) {
$currentYear = date('Y');
// Create choices array
$field['choices'] = array();
// Add blank first selection; remove if unnecessary
$field['choices'][''] = ' ';
// Loop through a range of years and add to field 'choices'. Change range as needed.
foreach(range($currentYear-1, $currentYear+5) as $year) {
$field['choices'][$number] = $year;
}
// Return the field
return $field;
}
add_filter('acf/load_field/key=field_0000000000000', 'sevenYearSelect');
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.