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;
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.