Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function filter_cars_dalinger()
- {
- $post_args = [
- 'my_marka' => FILTER_SANITIZE_STRING,
- 'my_model' => FILTER_SANITIZE_STRING,
- 'my_transmission' => FILTER_SANITIZE_STRING,
- 'my_fuel' => FILTER_SANITIZE_STRING,
- 'my_price-until' => FILTER_SANITIZE_NUMBER_FLOAT,
- 'my_price-after' => FILTER_SANITIZE_NUMBER_FLOAT
- ];
- $post = filter_input_array(INPUT_POST, $post_args);
- $paged = get_query_var('paged') ? get_query_var('paged') : 1; //новое
- if( isset ($post) )
- {
- // print_r($post);
- $args = array(
- 'numberposts' => -1,
- 'meta_key' => 'carsinfo',
- 'post_type' => 'cars',
- 'paged' => $paged, //новое
- 'tax_query' => array(
- 'relation' => 'AND'
- )
- );
- if($post['my_marka'] !== 'full')
- {
- array_push($args['tax_query'], array (
- 'taxonomy' => 'carmake',
- 'field' => 'term_id',
- 'terms' => array($post['my_marka']),
- ));
- }
- if($post['my_model'] !== 'full')
- {
- array_push($args['tax_query'], array (
- 'taxonomy' => 'carmake',
- 'field' => 'child_of',
- 'terms' => array($post['my_model']),
- ));
- }
- if($post['my_transmission'] !== 'full')
- {
- array_push($args['tax_query'], array (
- 'taxonomy' => 'transmission',
- 'field' => 'term_id',
- 'terms' => array($post['my_transmission']),
- ));
- }
- if($post['my_fuel'] !== 'full')
- {
- array_push($args['tax_query'], array (
- 'taxonomy' => 'fuel',
- 'field' => 'term_id',
- 'terms' => array($post['my_fuel']),
- ));
- }
- if( !empty( $post['my_price-until'] ) )
- {
- $args['meta_query'][] = array(
- 'key' => 'price',
- 'value' => $post['my_price-until'],
- 'type' => 'numeric',
- 'compare' => '>='
- );
- }
- if( !empty( $post['my_price-after'] ) )
- {
- $args['meta_query'][] = array(
- 'key' => 'price',
- 'value' => $post['my_price-after'],
- 'type' => 'numeric',
- 'compare' => '<='
- );
- }
- return new WP_Query($args);
- }
- else
- {
- $args = array(
- 'numberposts' => -1,
- 'meta_key' => 'carsinfo',
- 'post_type' => 'cars',
- 'current' => max( 1, get_query_var('paged') ),
- 'paged' => $paged //новое
- );
- return new WP_Query($args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement