Support

Account

Forum Replies Created

  • yes!
    I switched to term object, and it worked as expected, on new posts!

    Grazie mille (thanks a lot!)

  • Now the field is a Term ID, and it works, showing the numeric ID of my taxonomy.
    And is a radio field.

    Meanwhile i’ve uploaded my work in progress in a live server, with no improvements…

    I’ve found this code and it seems to work!

    <?php   // Get terms for post
     $terms = get_the_terms( $post->ID , 'tecnica' );
     // Loop over each item since it's an array
     if ( $terms != null ){
     foreach( $terms as $term ) {
     // Print the name method from $term which is an OBJECT
     print $term->name ;
     // Get rid of the other data stored in the object, since it's not needed
     unset($term);
    } } ?>

    from here, where is also suggested to use wp_get_object_terms( $object_ids, $taxonomies, $args )

    I’ve tried on new and old posts, changing the category changes correctly in the front end.

    Can we marked this [resolved]?
    Thanks again!

  • Wow!
    Thanks for the super quick reply!

    Unfortunately it didn’t do the magic.
    Actually, pretty weird, your code (with the right field name “tecnica”) doesn’t output anything at all!

    My code is:

    <?php if( get_field('tecnica') ): ?>
    <?php $field_name = "text_field"; $field = get_field_object(tecnica); echo $field['label']; ?>:<?php the_field('tecnica'); ?>
    <?php endif; ?>

    (i need the label too, for possible future translations)

    I’ve set it to use radio button, because i need just one category (the tecnique used for a painting,it’s for a painter catalogue).

    I’ve tried to set as an html select, or a multiple category,and i get the array, but always with the id.

    The code you suggested with the correct field ‘tecnica’ is

    $terms = get_field('tecnica');
    
    // if you are expecting a single value
    if (is_array($terms)) {
     $term = $terms[0];
    }
    echo $term->name;
    
    // if you are expecting an array
    if (!is_array($terms)) {
      $terms = array($terms);
    }
    foreach ($terms as $term) {
      echo $term->name;
    }

    I’m working on Xaamp on my old laptop, PHP Version is 5.6.14…

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