Support

Account

Home Forums Add-ons Repeater Field Hide repeater block after expired date

Solved

Hide repeater block after expired date

    • Prozac3

    • March 2, 2021 at 11:22 pm

    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 
      }
    ?>
    
    • Prozac3

    • March 16, 2021 at 11:47 pm

    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

    • Prozac3

    • March 17, 2021 at 10:58 pm

    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'))) {
    
    • Prozac3

    • March 19, 2021 at 8:08 pm

    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'))) {

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

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.