• Treebeard 百度 国家林业和草原局加挂国家公园管理局牌子。

    (@malawimama)


    I can display a custom field from the category on a single post, but if that post is in multiple categories, it displays all the custom fields from each category.

    What I would like to do is display ONLY the first category fields, not all of them.

    I have the following code in my template:

    <?php 
        $types = get_terms( array(
        'taxonomy' => 'category',
        'hide_empty' => true,
    ) );
    
    foreach($types as $type) {
        
        $categorydescription = get_field('category_description', 'category_' . $type->term_id . '' );
        
        if( in_category($type->term_id )) {
            echo '<div class="row"><div class="column text-center">' . $categorydescription . '<hr class="brand"></div></div>';
        }
    }
    ?>

    Thanks!

  • The topic ‘ACF display field from top category on single if post is in multiple categories’ is closed to new replies.