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?
Thank you for the quick response.
I am not that advanced when it comes to ACF (excuse the pun). Do you know how I could make the value the single image field?
Hi,
Thank you for the detailed feed. I have been struggling to get this working on my site for the past hour.
I am trying to set the first image in a repeater row as the featured image for each existing and new post.
The repeater is called sock_image and the image field is called sock_images. Any clue on what I am doing wrong? This is what I put in my functions file:
// Set the first sock image uploaded as the featured image
function acf_set_featured_image( $value, $post_id, $field ){
if($value != ''){
delete_post_thumbnail( $post_id);
//Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta($post_id, '_thumbnail_id', $value);
}
return $value;
}
// acf/update_value/name={$field_name} - filter for a specific field based on it's name
add_filter('acf/update_value/name=sock_images', 'acf_set_featured_image', 10, 3);