Support

Account

Home Forums General Issues Events Manager and ACF Reply To: Events Manager and ACF

  • I made an adjustment. It appears that the values in the array are strings at this point and they need to be integers.

    
    add_filter(
      'acf/load_value/name=YOUR_FIELD_NAME_HERE',
      'remove_expired_events_form_YOUR_FIELD_NAME_HERE',
      10, 3 
    );
    function remove_expired_events_form_YOUR_FIELD_NAME_HERE($value, $post_id, $field) {
      var_dump($value);
      if (!is_array($value) || !count($value)) {
        // bail early
        return $value;
      }
      $count = count($value);
      $now = time();
      for ($i=0; $i<$count; $i++) {
        // adjusted this line
        $expire = intval(get_post_meta(intval($value[$i]), '_end_ts', 0));
        if ($expire < $now) {
          unset($value[$i]);
        }
      }
      return $value;
    }