Support

Account

Home Forums Front-end Issues Front end show Taxonomies IDs instead of terms/name Reply To: Front end show Taxonomies IDs instead of terms/name

  • Salut aussi !
    Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂

    I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.

    My bad, I forgot to specify that I am also using Elementor.

    But here is what I have done:
    I have created a new taxonomy:
    https://prnt.sc/SblxWOHBmACi
    https://prnt.sc/QpWKI3Qa41-S
    https://prnt.sc/A8kIAtrZXW6m

    And here is what I did in Elementor:
    https://prnt.sc/kQmfuTbvomh1

    So it definitely loads something correct, which is the ID of the taxonomy:
    https://prnt.sc/2gf4eFlbn8tv
    In this case 59
    But even if I switch the value as showed in my original post this is still the ID and not the value/term that is showing up.

    It works fine with “normal” fields:
    https://prnt.sc/X–0v2gyJDCc
    https://prnt.sc/GwSsYtf4DpfC
    But I know this is not the same thing as Taxonomies.

    And I am a bit stuck :-/

    I even asked chatgpt to write me a code snippet which looks that it could have done something (I even asked the function to check on a specific url) but it still doesn’t work 🙁

    function convert_taxonomy_ids_to_terms( $value, $post_id, $field ) {
    if ( ! $value ) {
    return $value;
    }
    if ( strpos( $_SERVER[‘REQUEST_URI’], ‘/listing-des-animaux/’ ) !== false ) {
    $taxonomies = get_object_taxonomies( ‘animaux’ );
    if ( is_array( $value ) ) {
    $text_values = array();
    foreach ( $value as $id ) {
    foreach ( $taxonomies as $taxonomy ) {
    $term = get_term_by( ‘id’, $id, $taxonomy );
    if ( $term ) {
    $text_values[] = $term->name;
    }
    }
    }
    return implode( ‘, ‘, $text_values );
    } else {
    foreach ( $taxonomies as $taxonomy ) {
    $term = get_term_by( ‘id’, $value, $taxonomy );
    if ( $term ) {
    return $term->name;
    }
    }
    return $value;
    }
    } else {
    return $value;
    }
    }
    add_filter( ‘acf/format_value/type=taxonomy’, ‘convert_taxonomy_ids_to_terms’, 10, 3 );