Home Forums Front-end Issues get_field() in custom taxonomy


get_field() in custom taxonomy

  • Hello,

    I have some trouble to display fields on a custom taxonomy page, get_field() does not retrieve anything.

    For simple text fields I can use get_term_meta() instead and it works, but I have two others fields that are other taxonomy links that I need to display that can’t work with get_term_meta().

    Here is the code :

    <?php echo get_field( get_queried_object_id(), 'sports' ); ?>

    Did I forgot anything ?

  • this is backwards and does not contain the correct ID

    <?php echo get_field( get_queried_object_id(), 'sports' ); ?>

    You need

    $get_field($field_name, $post_id);

    $post_id can actually be an object or a string. When using a string you need to use "term_{$term_id}", but this really isn’t necessary. You could do

    <?php echo get_field('sports', get_queried_object()); ?>
  • I already tried with get_queried_object() but it returned an “array to string conversion” error.

    However, I found a better solution on the following link as I needed to display multiple values :

    Thanks for your help, though.

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

You must be logged in to reply to this topic.