Support

Account

Home Forums Front-end Issues subfields loop

Solved

subfields loop

  • Hello everyone, I have recently just purchased this plugin and have already started using it.

    So it’s not really an issue it’s more needing some help with the repeater and subfields.

    On the front end of the site I’m currently working on I’m trying to display each post with the relevant subfields that go with each post, this part is not an issue and is working how it should, the problem lies where it will only populate 1 subfield entry whereas I have 3.

    here is a snippet of my code to see if anyone can help or point me in the right direction, i have left out the rest of the code as its just html and the closing if and while statement. As you can see I’m trying to place the subfields in part of the table structure to get looped over, then I have that variable printing out in the table.

    I know its something to do with the way I have the while loops setup or its the way I am retrieving the subfields.

    function my_custom_giveaways($content){
    	$giveawayQuery = new WP_Query(array(
    		'post_type' => 'giveaways'
    	));
    	
    	global $post;		  
    	
    	$giveawayResult = '<div class="cgBox">';
    	$giveawayResult .= '<div class="cgBox-inner">';
    	$giveawayResult .= '<div class="cgBox-wrapper cgBoxes">';
    		
      if ( $giveawayQuery->have_posts() ) : while ( $giveawayQuery->have_posts() ) : $giveawayQuery->the_post();
      
      $theID = $post->ID;
      
      if ( have_rows('my_giveaways') ) : while ( have_rows('my_giveaways') ) : the_row();
    	  
    		  $place = get_sub_field('place', $theID);
    		  $prize_icon = get_sub_field('prize_icon', $theID);
    		  $prizes = get_sub_field('prizes', $theID);
    		  
    		  $giveawayBoxes = '<tr>
    				<td class="iconMid"><img src="' . $prize_icon . '" width="25" height="25" alt=""></td>
    				<td class="thePrize">' . $place . '<br>' . $prizes . '</td>
    			  </tr>';
    			  
    	endwhile;

    thanks in advance for any replies and it’s gratefully appreciated

  • UPDATE

    So i have had a look around on the documentation and tried a few things in which im half successful

    I used the_sub_field(sub_field_name) which outputs all of the rows but they output like an array would do, just all text and it displays in one big chunk above everything and if i change it to get_sub_field it only pulls in one row for each post but displays correctly

    here is the updated code

    function my_custom_giveaways($content){
    	$giveawayQuery = new WP_Query(array(
    		'post_type' => 'giveaways'
    	));
    	
    	global $post;		  
    	
    	$giveawayResult = '<div class="cgBox">';
    	$giveawayResult .= '<div class="cgBox-inner">';
    	$giveawayResult .= '<div class="cgBox-wrapper cgBoxes">';
    		
    		  if ( $giveawayQuery->have_posts() ) : while ( $giveawayQuery->have_posts() ) : $giveawayQuery->the_post();
    		  
    		  $theID = $post->ID;
    		  
    		  if ( have_rows('my_giveaways') ) : while ( have_rows('my_giveaways') ) : the_row();
    		  
    		  	$giveawayBoxes = '<tr>
    						<td class="iconMid"><img src="' . the_sub_field('prize_icon') . '" width="25" height="25" alt=""></td>
    						<td class="thePrize">' . the_sub_field('place') . '<br>' . the_sub_field('prizes') . '</td>
    					  </tr>';
    					  
    		endwhile;
    		  endif;
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.