Support

Account

Home Forums General Issues Display term of a custom taxonomy

Helping

Display term of a custom taxonomy

  • Hello everyone 🙂

    Not being a developer, I encounter some difficulties with customized taxonomies.

    Indeed, I would like to display the url of an image cover of the term chosen for an article. In my case, this is a car model.

    Here is my taxonomy:

    //hook into the init action and call create_book_taxonomies when it fires
    add_action( 'init', 'create_modeles_hierarchical_taxonomy', 0 );
    
    //create a custom taxonomy name it topics for your posts
    
    function create_modeles_hierarchical_taxonomy() {
    
    // Add new taxonomy, make it hierarchical like categories
    //first do the translations part for GUI
    
      $labels = array(
        'name' => _x( 'Modèles', 'taxonomy general name' ),
        'singular_name' => _x( 'Modèle', 'taxonomy singular name' ),
        'search_items' =>  __( 'Chercher un modèle' ),
        'all_items' => __( 'Tous les modèles' ),
        'parent_item' => __( 'Modèle parent' ),
        'parent_item_colon' => __( 'Modèle parent:' ),
        'edit_item' => __( 'Editer le modèle' ),
        'update_item' => __( 'Mettre à jour le modèle' ),
        'add_new_item' => __( 'Ajouter un modèle' ),
        'new_item_name' => __( 'Nouveau nom de modèle' ),
        'menu_name' => __( 'Modèle' ),
      );
    
    // Now register the taxonomy
    
      register_taxonomy('modeles',array('post'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'modele' ),
      ));
    
    }
    

    The name of the term is “cover_modele_voiture”

    Could someone help me?

    PS: I came across this documentation, which I do not understand https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/#overview

    Thank-you !

    Nathan.

  • Found ! If someone want…

    <?php $terms = get_the_terms( $post->ID , 'modeles' );foreach ( $terms as $term ) {echo the_field('cover_modele_voiture', $term);}?>

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

The topic ‘Display term of a custom taxonomy’ is closed to new replies.