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
Ahh brilliant, that did it for me. Thank you, James!
For my case I’ve added:
add_action( 'pre_get_posts', 'custom_orderby' );
function custom_orderby( $query ) {
if( ! is_admin() )
return;
$orderby = $query->get( 'orderby');
if( 'featured' == $orderby ) {
$query->set('meta_key','featured');
$query->set('orderby','meta_value');
}
elseif ( 'staff_order' == $orderby ) {
$query->set('meta_key','staff_order');
$query->set('orderby','meta_value_num');
}
elseif ( 'department' == $orderby ) {
$query->set('meta_key','department');
$query->set('orderby','meta_value');
}
}
I think this last function has to be added to the original Elliots article, maybe someone can pass it along :))
Thanks so much again!!!
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.