Hi @joelle,
By default, the plugin cannot display acf fields that have been added to other post/terms, as it can only display the acf fields for the post/page where the acf-vc integrator element has been added.
But as I understand your problem, it does not sound like something that this plugin can by default.
But I am writing it on my list so it should come in the future.
I can not put a date on it.
However, there is a way I think you will be able to solve the problem however requires some code.
What you need to do is add an acf taxonomy field to your post type books where you can select your Authors, this allows you to then use the acf-vc integrator to view a simple list view of your authors.
But using a hook you will be able to change how the content of the Taxonomy field is displayed and in that way get the image displayed.
You need to put the hook into your function.php in theme/child-theme.
add_filter( 'acfvc_taxonomy', 'acfvc_custom_taxonomy_output', 10, 3 );
function acfvc_custom_taxonomy_output ( $output, $field, $post_id ) {
return $output;
}
I hope it makes some sense.
Best regards
Frederik
Thread Starter
Joelle
(@joelle)
Hi, thank you so much for your help with this. I tried this, and I added the function to my child theme functions file.
Then I added the field to my Book custom fields related to that taxonomy and display it in a dropdown.
This is great, except it just displays the name and not the image. How can I call the image? The image field is in a separate field group. Should it be in the same field group?
Thread Starter
Joelle
(@joelle)
I *think* I get what you’re saying here… that I could feasibly have it display the taxonomy image instead of the name, but… I’m not sure how to do that. I’m guessing I need to build upon what you provided above (thank you!), but admittedly, I’m stuck.
Thoughts? 🙂
Hi @joelle,
I have made an example where an image is displayed instead of standard output.
‘acf_image’ this should be the name of your image field.
‘category_’ this should be your taxonomy slug and _ should be there after your taxonomy slug.
add_filter( 'acfvc_taxonomy', 'acfvc_custom_taxonomy_output', 10, 3 );
function acfvc_custom_taxonomy_output ( $output, $field, $post_id ) {
$output = '';
foreach ($field["value"] as $key => $term_id) {
$image = get_field( 'acf_image', 'category_'.$term_id );
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
$output .= wp_get_attachment_image( $image, $size );
}
}
return $output;
}
I hope this can help you
Best regards
Frederik
Thread Starter
Joelle
(@joelle)
Thank you so much, Frederick! I will give this a try, I appreciate your time. 🙂