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');
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.