Support

Account

Home Forums Add-ons Repeater Field get_sub_field_object – Selection Labels from Repeater

Solved

get_sub_field_object – Selection Labels from Repeater

  • Currently I am able to correctly display the VALUES just fine, but I can’t seem to pull the LABELS of my selection list items.

    current status

    Here is my current code:

    if( get_field('degrees', $post->ID) ) {
    	while ( have_rows('degrees', $post->ID) ) : the_row();
    		 $select = get_sub_field_object('degree_select', $post->ID);
    		 $value = $select['value'];	
    		 $listinfo .= ', ' . $value . '';
    	endwhile;
    }

    In my repeater selection list I have values written like:

    selection list

    So there is a VALUE and LABEL. The LABEL being the short acronym like Ph.D.

    In the repeater, I have things organized like this:

    repeater

    If I change my code to pull the LABEL instead of VALUE it just repeats the column title of “Degree Selection” over and over again and does not give me the actual selection label of Ph.D. for example.

    How can I fix this issue so that I display the LABEL (Ph.D) and not the VALUE (Doctor of Philosophy)?

  • I was able to resolve this issue by creating an array and then targeting the array column of LABEL.

    if( get_field('degrees', $post->ID) ) {
    	while ( have_rows('degrees', $post->ID) ) : the_row();
    		 $showDegree = array();
    		 $showDegree[] = get_sub_field('degree_select');
    		 $foo = implode(', ', array_column($showDegree, 'label'));
    			$listinfo .= ', ' . $foo . '';
    	endwhile;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.