Support

Account

Home Forums Backend Issues (wp-admin) Delete Repeater Row After Date

Helping

Delete Repeater Row After Date

  • I have created a custom Events section for the website I am working on. It works well. It has a Start Date, an End Date, and a Stop Showing Date. The event stops showing on the front-end on the End Date unless there is a Stop Showing Date entered. This allows an event to live a few days past it’s End Date on the front end.

    What I would like to do is to remove/hide/delete the event in the repeater on the BACK end after the End Date or Stop Showing Date have passed. I have some code already in functions.php to sort the events on the CMS side of the site so that the oldest is always at the top. The client could just delete these manually, but I was hoping to automate it. Here is my code for sorting the backend by end date ASC:

    add_filter('acf/load_value/name=event', 'my_acf_load_value', 10, 1); //repeater_name Second number must match the number of pages that use the Events Page template
    function my_acf_load_value( $rows)
    {
     foreach( $rows as $key => $row ) {
    	 $column_id[ $key ] = $row['field_593c050644713'];//This is the meta_value in SQL. Found in wp_postmeta table. meta_key = _event_0_event_end_date, meta_value = field_593c050644713
    }
     
     array_multisort( $column_id, SORT_ASC, $rows );
     return $rows;
    }
  • In order to do this you would need to set up a cron task https://codex.wordpress.org/Category:WP-Cron_Functions. In your cron you would need to get all of the posts, or whatever it is that this repeater is related to. The loop over this and check the row values and then use update_field() https://www.advancedcustomfields.com/resources/update_field/ or possibly delete_row https://www.advancedcustomfields.com/resources/delete_row/ to get rid of the ones you don’t want.

    Alternately, instead of using a cron you might be able to do this work inside of an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/, but this would only update the values for a post when it is updated.

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

The topic ‘Delete Repeater Row After Date’ is closed to new replies.