Support

Account

Home Forums Backend Issues (wp-admin) Add ACF field to post categories

Solved

Add ACF field to post categories

  • Hello,

    there is a way to add a field in post categories ?
    here

  • Under location rules for the field group.

    ACF 5: Taxomomy is equal to category
    ACF 4: Taxonomy Term is equal to Categories

  • thanks 🙂

    and to display it, we use:

    <?php 
     $category = get_the_category();
    
     $catID= $category->ID;
    get_field('subtitle_cat',  $catID ) ?>

    ?
    be cause it’s not working…

  • <?php 
     $category = get_the_category();
    get_field('subtitle_cat',  $category ) ?>
  • Thank you, but it’s not working

    <?php
    
    $category = get_the_category();
    $name= $category[0]->name;
    $slug= $category[0]->slug;
    $id = $category[0]->cat_ID;
    
    $sous_titre = get_field('sous_titre_categorie',  $category );
    ?>
    
    <div class="block-site title-cat" id="block-Apropos">
    				<h1><?php echo $name ?><br/>
    				<span> <?php echo $sous_titre ?></span>
    				
    				</h1>
    			</div>
  • get_the_category() returns an array of term objects, not a single term object, I didn’t realize this when I last commented.

    But is seems you figured that out since you’re using $name= $category[0]-> everywhere but for getting the field, so it should be. $sous_titre = get_field('sous_titre_categorie', $category[0] );

  • thanks it’s working 🙂

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

The topic ‘Add ACF field to post categories’ is closed to new replies.