Support

Account

Home Forums Add-ons Repeater Field Using radio button value in repeater field

Helping

Using radio button value in repeater field

  • I’m setting up a repeater for my client so she can manually add testimonials and the number of stars she was given with the testimonials. The radio button is for her to select the number of stars. I’ve seen a couple of threads on here about this, but I’m not sure how to go about reworking them for my set up. Here’s what I have so far:

    <?php
    // using normal array
    
    	$testimonialsections = get_field('testimonial_section');
    	$yelp_url = get_field('yelp_url', 'options');
    	$stars = $testimonialsections['stars'];
    
    	if ($stars == '1') {
    		echo "1";
    	}
    	
    	else if ($stars == '2') {
    		echo "2"; 
    	}
    	
    	else if ($stars == '3') {
    		echo "3"; 
    	}
    	
    	else if ($stars == '4') {
    		echo "4"; 
    	}
    	
    	else if ($stars == '5') {
    		echo "5"; 
    	}
    	
    	else {
    		echo ""; 
    	}
    
    	if($testimonialsections)
    	{
    		foreach($testimonialsections as $testimonialsection)
    		{
    		
    			echo 	'<div class="inner-test row">
    						<div class="col-md-12">
    							<p><span style="font-weight:bold">' .$testimonialsection['testimonial_author'].'</span><br/>
    							'.$stars.'</p>
    						</div>
    						
    						<div class="col-md-12">' .$testimonialsection['testimonial'].'
    						
    						<p><a href="'.$yelp_url.'" target="_blank">View More on Yelp!</a></p>
    						
    						</div>
    					</div>';
    		}
    	}
    
    ?>

    I’m trying an if/else statement, but that doesn’t seem to be working. Thoughts?

  • I feel so dumb right now. The answer was beyond simple. All I had to do was call the field using $testimonialsections['stars'];:

    Full answer (sorry that my indenting gets all screwy when I paste it in here):

    <?php
                           // using normal array
                         
                           $testimonialsections = get_field('testimonial_section');
    					   $yelp_url = get_field('yelp_url', 'options');
    					   
    					   
    					   
    					   
    	
    					   
                           if($testimonialsections)
                           {
                         
                               foreach($testimonialsections as $testimonialsection)
                               {
    							
    							   
    							   
                                   
                                   echo '<div class="inner-test row">
    										<div class="col-md-12">
    											<p><span style="font-weight:bold">' .$testimonialsection['testimonial_author'].'</span><br/>' .$testimonialsection['stars'].'</p>
    										</div>
    										<div class="col-md-12">
    										
    											' .$testimonialsection['testimonial'].'
    				
    											<a href="'.$yelp_url.'" target="_blank">View More on Yelp!</a>
    											
    										</div>
    									</div>';
                               }
                         
                            }
                         
                            ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.