Support

Account

Home Forums Front-end Issues How to get term field from taxonomy template

Solved

How to get term field from taxonomy template

  • Hi, building single term page, I’m trying to show an image field of a term in a custom taxonomy.

    Taxonomy: ‘personas’
    ACF image field: ‘fotopersonas’
    URL:http://localhost:3000/personas/my_term/’
    Template: ‘taxonomy-personas.php’

    This is the template content:

    get_the_archive_title();
    // I WANT TO GET HERE THE ACF IMAGE FIELD:
    $foto = get_field('fotopersona', $term);
    echo $foto;

    Also, I tried:

    $term_object = get_queried_object();
    print_r($term_object);
    $foto = get_field('fotopersona', $term_object->slug);
    echo $foto;

    With same results.

    Things that can help:

    When var_dump: $foto, I get:
    /srv/www/soux-calvo.dev/current/web/app/themes/sc/taxonomy-personas.php:8:boolean false (I don’t know why. This term has its field filled with an image).

    WHY?
    why can not I recover de ACF? In other templates with custom query, I can get the same field without problems.

    When
    $term_object = get_queried_object();
    var_dump($term_object);

    I get:

    object(WP_Term)[3177]
      public 'term_id' => int 4
      public 'name' => string 'Una Persona' (length=11)
      public 'slug' => string 'una-persona' (length=11)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 4
      public 'taxonomy' => string 'personas' (length=8)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 2
      public 'filter' => string 'raw' (length=3)

    Thanks!

  • I forget to mention: any attempt to get_field described above returns nothing.

  • Another clue:

    var_dump(get_fields($term_object->term_id));

    Returns:

    /srv/www/soux-calvo.dev/current/web/app/themes/sc/taxonomy-p‌​ersonas.php:10:boole‌​an false

  • $foto = get_field('fotopersona', 'personas'.'_'.$term_object->term_id);

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

The topic ‘How to get term field from taxonomy template’ is closed to new replies.