This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Issue with result group by meta key

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Issue with result group by meta key Reply To: Issue with result group by meta key

#22044
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Sure, it was possible with minor changes. I have changed one of the functions within the child theme directory, plase keep it there:

add_filter('asp_query_args', 'asp_reset_date_filter');
function asp_reset_date_filter($args) {
  if ( isset($_POST['autop']) ) {
    foreach ( $args['post_meta_filter'] as $k => $v ) {
      if ( $v['key'] == '_event_start' ) {
        unset($args['post_meta_filter'][$k]);
      }
    }
  } else {
    $val = '';
    foreach ( $args['post_meta_filter'] as $k => $v ) {
      if ( $v['key'] == '_event_start' ) {
        $val = $args['post_meta_filter'][$k]['value'];
      }
    }
    $val1 = date('Y-m-d', strtotime($val) - 24 * 60 * 60);
    $val2 = date('Y-m-d', strtotime($val) + 24 * 60 * 60);
    $args['post_meta_filter'] = array(
      array(
        'key' => '_event_start',
        'value' => $val2,
        'operator' => 'datetime <'
      ),
      array(
        'key' => '_event_end',
        'value' => $val1,
        'operator' => 'datetime >'
      )
    );
  }
  return $args;
}