Support

Account

Home Forums Add-ons Repeater Field Repeater Field from Custom Post Type won't Display…

Unread

Repeater Field from Custom Post Type won't Display…

  • Hi everyone! I work for a vacation home rental site in Florida called Homes4uu that was built using ACF shortly before I was added to the project. Over the last year I’ve been updating the site and getting more familiar with ACF. I’ve added a terms and conditions custom post type that we reuse, etc. I got it to work with minimal fuss so I moved onto my current project, which is adding a ‘rates and seasons’ template to the site. Basically we have hundreds of properties that all share the same date ranges and seasons, but with different prices. For example, August 15 to November 20th is Low season. So what I set up is a custom post type with a repeater field to enter the date ranges and seasons so when it comes time to update the dates, we only have to update the templates rather than 120+ individual properties. I also have a code snippet that calls up the low season price from the individual property when the date range season is ‘low’, ‘mid’ for ‘mid’ etc. Unfortunately…it doesn’t currently work. When the template is chosen, none of the data in the repeater field displays. It recognizes that I’ve chosen the template, the template saves properly…but nothing displays. I’ve read through a few forums, and the guides, but I’ve come to the point where I need a new set of eyes with a bit more experience in all things ACF.

    So Here is the code for the custom post type:

    register_field_group(array (
    	'id' => 'acf_rates',
    	'title' => 'Rates',
    	'fields' => array (array (
    		'key' => 'field_5a8fdfe319dec',
    		'label' => 'Rates per Date Ranges',
    		'name' => 'rates_per_date_template',
    		'type' => 'repeater',
    		'sub_fields' => array (
    		array (	'key' => 'field_5a8fe01d19ded',
    			'label' => 'Starting Date',
    			'name' => 'rates_start',
    			'type' => 'date_picker',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array('width' => '','class' => '','id' => '',),
    			'display_format' => 'm/d/Y',
    			'return_format' => 'Ymd',
    			'first_day' => 0,
    		),
    		array (	'key' 	=> 'field_5a8fe06b19dee',
    			'label' => 'Ending Date',
    			'name' 	=> 'rates_end',
    			'type' => 'date_picker',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array('width' => '','class' => '','id' => '',),
    			'display_format' => 'm/d/Y',
    			'return_format' => 'Ymd',
    			'first_day' => 0,
    		),
    		array(	'key' => 'field_5b47bf4e86700',
    			'label' => 'rates seasons',
    			'name' => 'rates_seasons',
    			'type' => 'select',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array('width' => '33','class' => '','id' => '',),
    			'choices' => array('Low' => 'Low',
    					   'Low and Mid' => 'Low and Mid',
    					'Mid' => 'Mid',
    					'High' => 'High',
    					'Holiday' => 'Holiday',	),
    			'default_value' => array(	),
    			'allow_null' => 0,
    			'multiple' => 0,
    			'ui' => 0,
    			'ajax' => 0,
    			'return_format' => 'value',
    			'placeholder' => '',	),
    		),
    		'row_min' => '',
    		'row_limit' => '',
    		'layout' => 'table',
    		'button_label' => 'Add Date Range',
    	),),

    This works, I can create the custom post types just fine, and the date range repeater is copied from the version used on the individual properties pages.

    Here is the code to call up the template in the property:

    array(	'key' => 'field_5b47cd1a17dfc',
    	'label' => 'Pick Rates Template',
    	'name' => 'rates_template',
    	'type' => 'relationship',
    	'instructions' => '',
    	'required' => 0,
    	'conditional_logic' => array(
    	array(	array(	'field' => 'field_5b47cccb17dfb',
    			'operator' => '==',
    			'value' => 'Yes',
    	),	),	),
    	'wrapper' 	=> array(	'width' => '', 'class' => '', 'id' => '', ),
    	'post_type' => array(	0 => 'rates',	),
    	'taxonomy' 	=> array(),
    	'filters' 	=> array(	0 => 'search',
    					1 => 'post_type',		),
    	'elements' 	=> '',
    	'min' 		=> '',
    	'max' 		=> '',
    	'return_format' => 'id',
    ),			

    This also works, because when I select a template the front end switches from the properly displayed rates (seen on this page):

    to what you see on this page under ‘rental rates and seasons’:
    https://www.homes4uu.com/vacation-properties/bella/

    So here is the code section that’s causing me problems, starting at *** to ### (I know everything before and after this section is working but its there so you have the full idea of the setup)

    $low	  = get_field('base_low_season_price');
    $mid	  = get_field('base_mid_season_price');
    $high	  = get_field('base_high_season_price');
    $holiday  = get_field('base_holiday_season_price');
    $rental_rates	= get_field('rental_rates');
    $rental_rands	= get_field('rates_and_seasons');
    if(get_field('rates_template')) { $rates = implode(get_field('rates'));}
    	$temp_rates = get_field('rates_template',$rates);
    if ($rates || $rental_rates || $rental_rands) : 
    echo '<a name="Rates"></a><br />';
      if ($temp_rates) :
    	echo'<h2 class="blue">Rental Rates & Seasons
                 <a href="#Top" class="totop">Back to Top</a></h2>
    <table class="rates" width="75%" cellpadding="0" cellspacing="0" cellcolor="#b7d8f9">
    <tbody><tr><th>Starting</th><th>Ending</th><th>Season</th><th>Rate</th></tr>';
    ***	
    if( have_rows('rates_per_date_template',$temp_rates) ):
    	while( have_rows('rates_per_date_template',$temp_rates) ) : the_row();
    		$rates_rows 	= get_row('rates_per_date_template');
            	$rates_start	= get_sub_field('rates_start');
            	$rates_end 	= get_sub_field('rates_end');
            	$rates_seasons 	= get_sub_field('rates_seasons');
    	foreach ($temp_rates as $temp_rate) :
            $currentdate = date("Ymd",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
            $starting = $rates_start;
    	$sy = substr($starting, 0, 4);
    	$sm = substr($starting, 4, 2);
    	$sd = substr($starting, 6, 2);
    	$tstime = strtotime("{$sd}-{$sm}-{$sy}");
    
    	$ending = $rates_end;
    	$ey = substr($ending, 0, 4);
    	$em = substr($ending, 4, 2);
    	$ed = substr($ending, 6, 2);
    	$tetime = strtotime("{$ed}-{$em}-{$ey}");
    							
    	if ($ending >= $currentdate) 							
    	{echo 	'<tr>	<td>'.date('F jS, Y',$tstime).'</td>
    			<td>'.date('F jS, Y',$tetime).'</td>
    			<td>'.$rates_seasons.'</td>';
    		switch ($rates_seasons) {
    			case "Low":	
    			echo '<td>'.$low.'</td>';
    			break;
    			case "Low and Mid":	
    			echo '<td>'.$low.'</td>';
    			break;
    			case "Mid":	
    			echo '<td>'.$mid.'</td>';
    			break;
    			case "High":	
    			echo '<td>'.$high.'</td>';
    			break;
    			case "Holiday":	
    			echo '<td>'.$holiday.'</td>';
    			break;
    		}
    		echo '</tr>';
    		}
    		endforeach;
    		endwhile;
    	endif;
    ###
    	elseif ($rental_rates) :
    echo '<h2 class="blue">Rental Rates & Seasons<a href="#Top" class="totop">Back to Top</a></h2>
    <table class="rates" width="75%" cellpadding="0" cellspacing="0" cellcolor="#b7d8f9"><tbody>
    <tr><th>Starting</th><th>Ending</th><th>Rate</th></tr>';
    $currentdate = date("Ymd",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
    foreach ($rental_rates as $rental_rate) :
    	$starting = $rental_rate['starting'];
    	$sy = substr($starting, 0, 4);
            $sm = substr($starting, 4, 2);
            $sd = substr($starting, 6, 2);
    	$stime = strtotime("{$sd}-{$sm}-{$sy}");
    	
            $ending = $rental_rate['ending'];
            $ey = substr($ending, 0, 4);
            $em = substr($ending, 4, 2);
            $ed = substr($ending, 6, 2);
    	$etime = strtotime("{$ed}-{$em}-{$ey}");
    	if ($ending >= $currentdate) 
    	{	echo 	'<tr>	<td>'.date('F jS, Y',$stime).'</td>
    			        <td>'.date('F jS, Y',$etime).'</td>
    				<td>'.$rental_rate['price'].'</td></tr>';
    	}
    	endforeach;
    	endif;
    echo '</tbody></table>';
    endif;

    I’ve tried a few things to make it work and I’m just stuck. So if anyone can read through this and see what I’m doing wrong I’d really *really* appreciate it! Also, if you could tell me *why* its wrong so I don’t do the same thing next time I try to call up a repeater from a custom post type on another page, which I will need to do in the future, I’d appreciate that as well! Thanks, Kate.

Viewing 1 post (of 1 total)

The topic ‘Repeater Field from Custom Post Type won't Display…’ is closed to new replies.