Home › Forums › General Issues › Order by ACF › Reply To: Order by ACF
Thank you John,
As a beginner I am still not able to get it working this way. This is the code I have:
In my functions.php file:
function my_sort_function($a, $b) {
if ($a->star_rating == $b->star_rating) {
return 0;
} elseif ($a->star_rating < $b->star_rating) {
return -1;
} else {
return 1;
}
}
On my home page:
<?php
$args = array(
'taxonomy' => 'sock-club',
'hide_empty' => '0'
);
$terms = get_terms('sock-club', $args);
if ($terms) {
foreach ($terms as $index => $term) {
$terms[$index]->star_rating = get_field('star_rating', $taxonomy.'_'$term_id);
$term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
}
usort($terms, 'my_sort_function');
}
?>
Can you see what is wrong with my code?
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.