Support

Account

Home Forums General Issues Sorting custom columns with custom fields sorts only by date Reply To: Sorting custom columns with custom fields sorts only by date

  • Interesting topic that helped me sort my /true/false custom fields column.
    It’s all working, but the initial sorting for true / false fields will be asc and we want desc.
    Adding this code under each conditional will fix that :

            $orderdir = $query->get( 'order');
            if('desc' == $orderdir) {
                $query->set('order','asc');
            } else {    
                $query->set('order','desc');
            }
    

    final result :

    		
    if( 'featured' == $orderby ) {
    $query->set('meta_key','featured');
    $query->set('orderby','meta_value');
    $orderdir = $query->get( 'order');
      if('desc' == $orderdir) {
           $query->set('order','asc');
          } else {    
            $query->set('order','desc');
           }
    }