Support

Account

Home Forums Add-ons Repeater Field Using array_unique with repeater fields to remove duplicate @font-face requests Reply To: Using array_unique with repeater fields to remove duplicate @font-face requests

  • I managed to solve this myself. According to this post, it looks as though array_unique doesn’t work with sub_field text strings on ACF. Instead, using an if !in_array command worked fine, as seen in the below example:

    if( have_rows('global_typography', 'option') ):
        while( have_rows('global_typography', 'option') ) : the_row();          
            // display your sub fields
            $custom_font_file = get_sub_field('global_custom_font_file');
            // compare current value in saved array
            if( !in_array( $custom_font_file, $PreValue ) )
                {
                print '@font-face {' . PHP_EOL;
                print 'font-family: '; the_sub_field('global_custom_font_family_name'); print ';' . PHP_EOL;
                print "src: url('"; the_sub_field('global_custom_font_file'); print "');" . PHP_EOL;
                print 'font-weight: normal;' . PHP_EOL;
                print '}' . PHP_EOL  . PHP_EOL;
                }
            // save value in array
            $PreValue[] = $custom_font_file;
        endwhile;
    endif;