Home › Forums › Add-ons › Repeater Field › Hide repeater block after expired date
Hi,
I want to create a daily offer for each day of the week. I have repeater fields and code:
<?php if ( have_rows( 'daily-offer', 'option' ) ) : ?>
<?php while ( have_rows( 'daily-offer', 'option' ) ) : the_row(); ?>
<?php the_sub_field( 'title' ); ?>
<?php the_sub_field( 'date' ); ?>
<?php the_sub_field( 'content' ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
How to make the block delete automatically after the entered date? the_sub_field “date” is selected using the datepicker.
<?php
if (have_rows('daily-offer', 'option')) {
while (have_rows('daily-offer', 'option')) {
the_row();
if (get_sub_field('date', false, false) > date('Ymd')) {
the_sub_field('title');
the_sub_field('date');
the_sub_field('content');
}
}
} else {
// no rows found
}
?>
Many thanks John Huebner.
But this code deletes the entry when the date starts. I need the entry to be deleted when the date expires.
For example, in addition to yesterday, it does not display today’s date.
Then compare it with the end date sub field instead of the start
get_sub_field('....'
whatever that field name is
I’m sorry John, I’m a designer and I can’t program. I don’t understand what you mean? Maybe you can add me the code here?
I’m going to need more to work with.
I assume you have a repeater and you have a sub field that indicates the end date. You did not give the name of this field.
This is checking the date field you included in OP
if (get_sub_field('date', false, false) > date('Ymd')) {
You need to change the field name in this if statement to your end date field name
There would be almost no way to do this without it except to maybe do something like
if (get_sub_field('date', false, false) > date('Ymd', strtotime('+1 day'))) {
Thank you very much for your co-thinking John!
I got it to work
if (get_sub_field('date', false, false) > date('Ymd', strtotime('-1 day'))) {
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!
After @keithdevon mentioned building out an accessible @wp_acf accordion block I went through my starter theme, setup a new site and just tabbed through it... try it, you'll end looking at your websites in a completely different light! Fully accessible navigation and content now.
— Paul Jackson (@pixelsandthings) April 5, 2021
© 2021 Advanced Custom Fields. Subscribe
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.