Search code examples
wordpressadvanced-custom-fieldscustom-taxonomyacfpro

ACF custom fields not displaying on custom taxonomy template


I have created a custom taxonomy called inn-features, I have then created a template page, whenever I try to show my custom fields the value always returns as null. Please can someone tell me where I am going wrong.

This is a really simplified version of the code as I stripped everything out to see where I am going wrong but I can't figure it out.

The var dump for each displays the following

<?php
/**
 * The template for displaying taxonomy archive pages
 *
 */



// get the current taxonomy term
$queried_object = get_queried_object(); 
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;  



// vars
$test = get_field('test_text', $taxonomy);

    var_dump($queried_object);

    var_dump($taxonomy);

    var_dump($term_id);

    var_dump($test);

    ?>

$queried_object, $taxonomy & $term_id all return values it is purely $test that returns null.


Solution

  • I eventually sorted it out by doing:

    $term = get_queried_object();
    
    $test = get_field('test_text',$term);
    

    This fixed it for me.