Support

Account

Home Forums General Issues Loop acf/load_field with 'foreach' Reply To: Loop acf/load_field with 'foreach'

  • Hi John,

    I found the solution to this problem by using php function ‘use’. See below.

    Thanks for your help!

    $select_fields = array( 'cornices', 'bedrooms-flooring' );
    
    foreach ( $select_fields as $var ) {
    add_filter('acf/load_field/name='.$var.'-select', function ( $field ) use ($var) { 
    
    // some code using $var
           
    });
    }