Hi there all, hoping I can get some assistance with a project I am working on that is stumping me at two junctions. The first has to do with repeater fields. No matter what I do, I can not get a repeater field to show any values whatsoever. I have tried a great number of codes that I have found across the web. I figured it may be easier to explain what I am looking to accomplish and then what my fields look like.
I have created a custom post type for events in wordpress via a plugin and I am looking to use the single-events.php page to display the custom fields that are assigned to the post type. See the ACF screenshot attached to see how the fields are named. Ive tried to loop through the rows with the instructions for the repeater field here on the support site. My goal is to display the two repeater fields info in the format:
option_name – option_price
The second issue im having is with a code that I used to conditionally display the when information for an event based on it being either a multi day event or a single day event. The difference between the two being that an all day event is only from a date to a date and a single day event is from a date and from time to a to time. Everything works, except no matter what I do the $start_date_only always reports back the UNIX default 1970 date. Any help on both matters would be greatly appreciated, Im a week into PHP and stumped on these two.
CODE:
<div class="row" align="center"><h3>WHEN</h3></div>
<?php
$event_type = get_field('event_type');
$start_date = get_field('event_start');
$start_date = date("F j, Y g:i a", strtotime($start_date));
$start_date_only = new DateTime($start_date);
$start_date_only = $start_date_only->format('F j, Y');
$start_time_only = new DateTime($start_date);
$start_time_only = $start_time_only->format('g:i a');
$end_date = get_field('event_end_date');
$end_date = date("F j, Y g:i a", strtotime($end_date));
$end_date_only = new DateTime($end_date);
$end_date_only = $end_date_only->format('F j, Y');
$end_time_only = new DateTime($end_date);
$end_time_only = $end_time_only->format('g:i a');
ob_start(); //Start output buffer
echo $start_date_only . " to " . $end_date_only;
$start_end_date = ob_get_contents(); //Grab output
ob_end_clean(); //Discard output buffer
ob_start(); //Start output buffer
echo $start_date_only . " from " . $start_time_only . " to " . $end_time_only;
$date_and_time = ob_get_contents();
ob_end_clean(); //Discard output buffer
?>
<div class="row" align="center"><h3><?php echo "$start_end_date"; ?></h3></div>
<div class="row">
<div class="row" align="center"><h3>WHERE</h3></div>
<div class="row" align="center"><h3><?php the_field('event_location_name') ?><br><?php the_field('event_location_address'); ?></h3></div>
</div>
For your first issue, groupings are treated similar to repeater fields but there is a single row of data in that value.
Visually, it appears as a repeater within a repeater.
<?php
// Check for grouping.
if ( have_rows( 'price_information' ) ) :
while ( have_rows( 'price_information' ) ) : the_row();
// Check for repeater.
if ( have_rows( 'event_cost_structure' ) ) :
// Loop through the rows of data.
while ( have_rows( 'event_cost_structure' ) ) : the_row(); ?>
<p><?php the_sub_field( 'option_name' ); ?> : <?php the_sub_field( 'option_price' ); ?></p>
<?php
endwhile;
endif;
endwhile;
else :
// No rows found.
endif; ?>
For the second issue, it seems to format the date correctly on my end…What are your organizations and settings in regards to the display/return format for the Date Picker?
The topic ‘Two Issues… Repeater Display and DateTime 1970’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.