Home Forums ACF PRO Unique identifier for each flexible field?


Unique identifier for each flexible field?

  • Hi everyone,
    Is there a way to display a value unique to each flexible content item so that I can use that value in CSS?

    I have a flexible content repeating multiple Wysiwyg containers on a single page. I need to isolate each one with a unique class tag that will not be repeated but is permanent so it CSS can be applied to it.

    something like uniqid() but static.

  • I solved the problem by creating a php counter

    column-block-# where # is 1, 2, 3, 4 etc. until the repeat ends. see code below.

    // check if the nested repeater field has rows of data
            	if( have_rows('column_repeater') ):
    			 	echo '<ul class="small-block-grid-' . $number_columns . '">';
    			 	// loop through the rows of data
    			    while ( have_rows('column_repeater') ) : the_row();
    					if (empty($counter)){
    					   $counter = 'column-block-' . 1;
    				$content = get_sub_field ('column_content');
    					echo '<li><div class="' . $counter . '">' . $content . '</div></li>';
    				echo '</ul>';
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Unique identifier for each flexible field?’ is closed to new replies.