Support

Account

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

  • 
    
    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) {
    	//return $value;
      if (!is_array($value) || !count($value)) {
        // bail early
        return $value;
      }
      $count = count($value);
      $now = time();
      for ($i=0; $i<$count; $i++) {
    		$post_type = get_post_type(intval($value[$i]));
        $expire = intval(get_post_meta(intval($value[$i]), '_end_ts', true));
        if ($post_type == 'event' && $expire < $now) {
          unset($value[$i]);
        }
      }
      return $value;
    }