• Hello! I’ve seen some others similar to this, but I’m not sure how to display the image.

    I’ve got a custom post type, Books.
    I’ve got a custom taxonomy, Authors.
    In Authors, I’ve added an ACF custom field for the author image.
    In my Book edit screen, I’ve added the WPBakery element for the VC-ACF Integrator, selected the field group and field I want to use.
    When I save the Book and try to view it, it shows me all my other fields, but not the Author taxonomy custom field for an image.

    Now, this is also the only custom field associated with the taxonomy, not the post type itself, could that be it? The Book post type is categorized with an Author term and has a photo uploaded to that term. If the Book post is categorized with that term, shouldn’t it show that field?

    I’d appreciate any help you can offer. ?? thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    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? ??

    Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    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. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ACF Image in Custom Taxonomy Not Showing in Post’ is closed to new replies.