Support

Account

Home Forums Front-end Issues Show ACF field of taxonomy "category" in template

Helping

Show ACF field of taxonomy "category" in template

  • Hi everyone, i have the following problem:

    This is my initial situation:

    1. I have a frontpage where i want to show 4 posts of a “current” category. (it is working)

    2. This “current” category is selected on the page “frontpage” with an acf field type “taxonomy” (it is working)

    3. The taxonomy “category” (standard taxonomy of posts) has an acf field “image”. So i can select 1 image at each category. The output of the field is “url”.

    4. Now i want to show the image only of the “current” category (the selected category on the page “frontpage) on my frontpage.

    I tries so many codes but nothing worked.

    I think i have to add something like: $term->taxonomy … but i dont know how…

    This is my latest code on frontpage.php (own theme):

    <?php
    	$currentcat = get_field('aktuelle_ausgabe');
    
    	if( in_category( '$currentcat' ) ) {
    		echo do_shortcode( '[acf field="titelbild"]');
    	}
    	else {
    		echo 'nope';
    	}
    	?>

    Can anyone help me?

  • When getting fields from categories (terms) you must supply the correct $post_id value for the ACF function the_field('image', $post_id); The post_id for a category is "{$taxonomy_name}_{$term_id}" In this case that means is should look something like 'category_101'. For more information see the “Get a value from other places” section of this page https://www.advancedcustomfields.com/resources/get_field/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Show ACF field of taxonomy "category" in template’ is closed to new replies.