Support

Account

Home Forums Backend Issues (wp-admin) year picker

Solved

year picker

  • Does anyone know if it’s possible to use a date picker with the year only(drop down with years) or should I use a select field type? Thanks!

  • I would use a select field.

  • 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');
  • Thank you for the snippet!

    Juste $number should be $year.

    $field['choices'][$number] = $year; => $field['choices'][$year] = $year;

  • How can I add this snippet? I’m using the “Snippets” plugin but no additional field types are showing with this function added via snippets.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘year picker’ is closed to new replies.