Sorting problem price

Question

I have a sorting problem when I do a search the titles are also taken into account whereas I would only like to manage it by price. Thank you.

 $args  = array( 
            'post_type'           => array('product', 'product_variation'),
            'post_status'         => 'publish',
            'posts_per_page' => get_option('posts_per_page'),
            'paged'          => $paged,
            'tax_query'      => $tax_query,
            'orderby'       =>  (isset($_GET["orderby"])?$_GET["orderby"]:'meta_value_num'),
            'order'         => (isset($_GET["order"])?$_GET["order"]:'ASC'),
         );
   


 if ($orderby == 'price') {

    $args['orderby'] = 'meta_value_num';
    
    $args['meta_key'] = '_price';
    
    $args['order'] = 'asc';


  } elseif ($orderby == 'price-desc'){
    
    $args['orderby'] = 'meta_value_num';
    
    $args['meta_key'] = '_price';
    
    $args['order'] = 'desc';   } 

        

 $content .='<select class="dropdown-class" name="sort-posts" id="sortbox" onchange="document.location.href=location.href+this.options[this.selectedIndex].value;"><option enabled>Trier par</option>';
 $content .='<option value="?orderby=price&order=asc">Trier par tarif croissant</option>';
 $content .='<option value="?orderby=price&order=desc">Trier par tarif décroissant</option>';
 $content .='</select>';
0
Mourcely Quentin 2 years 2020-10-22T04:10:51-05:00 0 Answers 12 views 0

Leave an answer

Browse
Browse