1. Home
  2. Car Demon Code Docs
  3. Display Filters
  4. cd_query_filter

cd_query_filter

This filter can be used to adjust the vehicle search or display query.

apply_filters( ‘cd_query_filter’, $car_query );

Example usage:

add_filter( 'car_demon_query_filter', 'my_car_query', 10, 1 );

function my_car_query( $query ) {
 //= $query contains the current vehicle query
 $year = date( 'Y', time() );
 $month = date( 'm', time() );
 $day = date( 'd', time() );

 //= get timestamp from 5 days ago
 $days_ago_timestamp = strtotime( '-4 days' );
 $do_year = date( 'Y', $days_ago_timestamp );
 $do_month = date( 'm', $days_ago_timestamp );
 $do_day = date( 'd', $days_ago_timestamp );

 $query['date_query'] = array(
     array(
         'after' => array(
         'year' => $do_year,
         'month' => $do_month,
         'day' => $do_day,
     ),
     'before' => array(
         'year' => $year,
         'month' => $month,
         'day' => $day,
         ),
     'inclusive' => true,
     ),
 );
 return $query;
}

The example above would modify the query to only display cars added in the last 5 days.

Was this article helpful to you? Yes No

How can we help?