Support

Account

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

Solved

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

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

You must be logged in to reply to this topic.