Example #1
0
 function st_vc_list_cars($attr, $content = false)
 {
     $data_vc = STCars::get_taxonomy_and_id_term_car();
     $param = array('st_ids' => '', 'taxonomy' => '', 'st_number_cars' => 4, 'st_order' => '', 'st_orderby' => '', 'st_cars_of_row' => 4, 'sort_taxonomy' => '', 'st_location' => '');
     $param = array_merge($param, $data_vc['list_id_vc']);
     $data = wp_parse_args($attr, $param);
     extract($data);
     $query = array('post_type' => 'st_cars', 'posts_per_page' => $st_number_cars, 'order' => $st_order, 'orderby' => $st_orderby);
     if (!empty($st_ids)) {
         $query['post__in'] = explode(',', $st_ids);
         $query['orderby'] = 'post__in';
     }
     if ($st_orderby == 'sale') {
         $query['meta_key'] = 'cars_price';
         $query['orderby'] = 'meta_value';
     }
     if ($st_orderby == 'featured') {
         $query['meta_key'] = 'is_featured';
         $query['orderby'] = 'meta_value';
     }
     if (!empty($sort_taxonomy)) {
         if (isset($attr["id_term_" . $sort_taxonomy])) {
             $id_term = $attr["id_term_" . $sort_taxonomy];
             $query['tax_query'] = array(array('taxonomy' => $sort_taxonomy, 'field' => 'id', 'terms' => explode(',', $id_term)));
         }
     }
     if (!empty($st_location)) {
         $query['meta_query'][] = array('key' => 'id_location', 'value' => $st_location, 'compare' => "IN");
     }
     query_posts($query);
     $txt = '';
     while (have_posts()) {
         the_post();
         $txt .= st()->load_template('vc-elements/st-list-cars/loop', 'list', array('attr' => $attr, 'data_' => $data));
     }
     wp_reset_query();
     return '<div class="row row-wrap">' . $txt . '</div>';
 }