• Resolved chathurika0526

    (@chathurika0526)


    using get_term_meta($term_id, ‘cc_color’, true); function.But can not get color return null value.How I get the color ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Gesundheit Bewegt GmbH

    (@loyaltymanufaktur)

    Hello chathurika0526,

    This function only works if a color has been previously assigned to the term, using get_term_meta() or in the backend taxonomy page.

    Thread Starter chathurika0526

    (@chathurika0526)

    Thank you for your quick reply.I found my mistake.

    Hello , i display my categories like this.

    <?php

    $terms = get_terms( ‘arthra_categories’);

    foreach ( $terms as $category ) {
    $term_list .= ‘<a class=”col-12 col-md-12 col-lg-6″ href=”‘ . esc_url(
    get_term_link( $category ) ) . ‘” alt=”‘ . esc_attr( sprintf( __( ‘View all post
    filed under %s’, ‘my_localization_domain’ ), $category->name ) ) . ‘”>’ .
    $category->name . ‘‘;

    }
    echo $term_list;?>

    I think i should put the code get_term_meta($term_id, ‘cc_color’, true); under $terms = get_terms( ‘arthra_categories’);

    But then what i will have to do?

    Thank you

    Plugin Author Gesundheit Bewegt GmbH

    (@loyaltymanufaktur)

    Hello mula4,

    try this:

    foreach ( $terms as $category ) {
    $color = get_term_meta($category->term_id, 'cc_color', true);

    Hello,

    i tried but the generated code is the code below.

    https://prntscr.com/nafujb

    How can i use the value $color as a background color of the tag?

    Plugin Author Gesundheit Bewegt GmbH

    (@loyaltymanufaktur)

    <a class="col-12 col-md-12 col-lg-6" style="background-color: <?php echo $color ?>" ...

    P.S. Instead of get_term_meta(..) better to use
    ColorfulCategories::getColorForTerm($category->term_id);

    The final code that worked is ”

    foreach ( $terms as $category ) {
    $color = ColorfulCategories::getColorForTerm($category->term_id);
    $term_list .= ‘<a class=”col-12 col-md-12 col-lg-6″ style=”background-color: ‘.
    $color .'” href=”‘ . esc_url( get_term_link( $category ) ) . ‘” alt=”‘ .
    esc_attr(
    sprintf( __( ‘View all post filed under %s’, ‘my_localization_domain’ ),
    $category->name ) ) . ‘”>’ . $category->name . ‘‘;
    }
    echo $term_list;?>

    thank you very much for your help!

    Plugin Author Gesundheit Bewegt GmbH

    (@loyaltymanufaktur)

    You are welcome

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How To Get Color’ is closed to new replies.