Home Forums Front-end Issues can't print taxonomy field name


can't print taxonomy field name

  • I created a taxonomy field “corso” visible in user profile to associate a course to a single user.

    I need the field id and field name both, but it return only id.

    How can I print field name?

    $corso_id = get_field('corso', 'user_'.$current_user->ID );
    echo $corso_id['label'].': '.$corso_id;


  • get_field() only returns the value in the field, in this case it’s returning the term ID, which means you have it set to return the term ID. Are you trying to display the name of the term? or some other label?

  • I’m trying to display name of term field that is associated in user profile…

    in acf i set: type field “taxonomy” and value term id (I test object term too but it doesn’t work)
    and in user profile I set one of course in select.

  • I’m still a little confused. Are you trying to show the label of the ACF field or the label for the selected term?

    If you want to get information about the ACF field then use

    $field = get_field_object($field_key); // use the field key, not the field name
    echo $field['label'];

    if you are trying to display the term name then set the field to return object and use

    $term = get_field('field_name');
    echo $term->name;
  • sorry, maybe it’s for my bad english…
    i tested both your solution but nothing… : (

    I created a select to display my taxonomy in single user profile

    as you can see in the image (, I associated the “training pratico” course to “utenteprova”.

    I want to get id and name of taxonomy of current user
    (in this case UTENTEPROVA has TRAINING-PRATICO with ID 7)

    I need to redirect users after login, so I need something like this

    'redirect' => get_option('siteurl').'/corsi/training-pratico

    but I can’t display slug training-pratico

    another possible solution could be

    $corso_id = get_field('corso', 'user_'.$current_user->ID );
    'redirect' => get_option('siteurl').'/?corsi='.$corso_id 

    it return /?corsi=7

    but it’s a not found page.. Do it exist a permalink to term of taxonomy?

    In admin is:


  • You need to return an object form the taxonomy field

    $current_user = get_current_user_id();
    $term = get_field('corso', 'user_'.$current_user);
    echo $term->term_id,'<br />',$term->name;
  • doesn’t work…
    in page.php I do an inclusion:
    if (is_page(145)) { include ('area_riservata.php'); }

    I shared code of this page here:

  • On line 30 you have

    $corso_id2 = get_field_object($corso_key, 'user_'.$current_user->ID);

    just before that echo out $current_user->ID

    echo $current_user->ID;
    $corso_id2 = get_field_object($corso_key, 'user_'.$current_user->ID);

    what is displayed?

  • It’s displayed “1” (I login as administrator)

    in header.php I put:

    global $current_user;
    $current_user = wp_get_current_user();
    $user_verify = wp_signon( $login_data, true );
  • I can’t really read anything in the images you supplied before, so I can’t tell much by looking at them.

    Your problem may be that ACF is unable to return the term, now that I think about it this is more than likely the case. WP does not really support user terms and because of this ACF probably is not returning anything.

    See this discussion for more information about user taxonomies

    You should probably return the term ID and not try to return the term Object and then get the term yourself

    $corso_id2 = get_field_object($corso_key, 'user_'.$current_user->ID);
    $term = get_term_by('id', $corso_id2, $taxonomy, 'OBJECT');


  • nothing… 🙁

    I solved with “peter login redirect” plugin.

    With ACF field I can manage various controls through the id of the course but not redirect.

    With plugin all right : )

    anyway… thanks very much!!!

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

The topic ‘can't print taxonomy field name’ is closed to new replies.