Home › Forums › Add-ons › Repeater Field › Repeater Sub-field 'Date' in array
Hi,
I am trying to call Repeater Sub-field ‘Date’ in array. But I am not aware with this how to fetch data in array. I want to display the content according to selected.I am sharing my code below please let me know how ca l fetch the data according to data.
`<div class=”container”>
<div class=”row”>
<div class=”sp30″></div> <div class=”sp30″></div>
<div class=”alert alert-warning” role=”alert”>
Select the Date:
<!– Example single danger button –>
<div class=”btn-group”>
<?php $today_date= date(“Y-m-d”) ;?>
<form action=”” method=”POST” name=”date”>
<select name=”date-time” onchange=’this.form.submit()’>
<option value=””>Select Date </option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week monday’)); ?>”>Monday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week monday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week tuesday’)); ?>”>Tuesday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week tuesday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week wednesday’)); ?>”>Wednesday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week wednesday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week thursday’)); ?>”>Thursday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week thursday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week friday’)); ?>”>Friday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week friday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week saturday’)); ?>”>Saturday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week saturday’)); ?></option>
<option value=”<?php echo $date = date(“Y-m-d”,strtotime(‘this week sunday’)); ?>”>Sunday – <?php echo $date = date(“Y-m-d”,strtotime(‘this week sunday’)); ?></option>
</select>
<!–<input type=”date” data-date=”” data-date-format=”YYYY MMMM DD” name=”sdate”>–>
<!–<input type=”date” name=”date” id=”date” pattern=”dd/mm/yyyy”/>–>
<noscript><input type=”submit” value=”Show Serials” name=”data”/></noscript>
<?php $select_date= $_REQUEST[‘date-time’];
echo $rep_date = str_replace(‘-‘, ”, $select_date);
?>
</form>
</div>
</div>
</div>
<?php
$paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;
// args
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘serial’,
‘meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘date’,
‘compare’ => ‘LIKE’,
‘value’ => $rep_date,
)
)
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<!——-new cards——->
<div class=”card-deck”>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if( have_rows(‘other_information’) ):
while ( have_rows(‘other_information’) ) : the_row();
// Your loop code
?>
<div class=”card text-center”>
” style=”width:253px; height:180px”alt=”Card image cap”>
<div class=”card-block”>
<h5 class=”card-title”><?php the_sub_field(‘program_name’); ?></h5>
<h6 class=”card-footer”><?php the_sub_field(‘repeat__regular’); ?> | <?php the_sub_field(‘time’); ?></h6>
” class=”btn btn-danger btn-lg btn-block”><i class=”fa fa-video-camera” aria-hidden=”true”></i> Watch Latest Episode
</div>
<?php the_sub_field(‘date’); ?>
</div>
<?php endwhile;
else :
// no rows found
endif;?>
<?php endwhile; ?>
</div>
<!——-end cards——>
<?php else : ?>
<?php echo “Please choose Another Date”; ?>
<?php endif; ?>
<!–Start pagination–>
<?php /*?>
<?php
$total_pages = $the_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var(‘paged’));
echo paginate_links(array(
‘base’ => get_pagenum_link(1) . ‘%_%’,
‘format’ => ‘page/%#%’,
‘current’ => $current_page,
‘total’ => $total_pages,
‘prev_next’ => False,
‘type’ => ‘list’,
));
}
?>
<?php */?>
<!–end pagination–>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div>
Do you want to select all posts with the selected date from the form?
If so you can use something like this:
https://support.advancedcustomfields.com/forums/topic/order-by-subfield-values/
You can rework it for a meta_query like this:
'meta_query' => array(
array(
'key' => 'other_information_%_date',
'compare' => 'LIKE',
'value' => $rep_date,
'type' => 'DATE' //May not be necessary
)
Hope that helps, or if you got another solution I would love to see it 😀
You must be logged in to reply to this topic.
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.