Forum Replies Created

  • 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');
  • Thanks John. This looks like it could be an ambitious project for my level. But very keen to give it a crack and learn some new things. Thanks for setting me on the right path! I really appreciate it.

  • Thanks John, the critical error was something else. Have fixed everything with your comments. And it’s now working perfectly. Thank you so much. You’ve been a huge help.

  • Ah thank you John! I did try that, but I must’ve made another mistake. Turns out it was an easy fix! Thank you very much.

  • I finally got it! I think I wasn’t declaring my variables clearly enough.

    $row = get_field( 'document' );
    $first_row = $row[0];
    $first_row_file = $first_row[ 'file' ];
        if( $first_row_file ) :
            		$download = '<div>Available!<div>This document is ready for download.</div></div>' ;
            				echo $download;
        else :
            		$unavailable = '<div>Unavailable!<div>This document isn\'t ready yet. Please check back later.</div></div>' ;
            				echo $unavailable;

    Now I can add more sophisticated content (like a download button) to display when there is a file to download, and a helpful message when there isn’t.

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