Home › Forums › General Issues › Can’t sort with an ACF field? › Reply To: Can’t sort with an ACF field?
There was an error sorry :
function custom_order_by_acf_field_query($query) {
if (!is_admin() && isset($query->query_vars['orderby'])) {
// Récupérer le champ ACF entre {{}}
$orderby_field = str_replace(array('{{', '}}'), '', $query->query_vars['orderby']);
if ( $orderby_field != $query->query_vars['orderby']) {
$query->set('meta_key', $orderby_field);
$query->set('orderby', 'meta_value_num');
}
}
}
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.