• Resolved alexadark

    (@alexadark)


    Hi,
    i am trying to have an image on custom taxonomy archive pages
    so i create the custom field

    Container::make('term_meta', 'Menus Images')
             ->show_on_taxonomy('menus')
             ->add_fields(array(
    	         Field::make('image', 'crb_hero_tax_image',__('Hero Image',CHILD_TEXT_DOMAIN)),
             ));

    but to retrieve it i don’t know what to write in place of $term

    $image_id = carbon_get_term_meta($term->term_id,'crb_hero_tax_image');

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter alexadark

    (@alexadark)

    Hi,
    i have found the solution, and created a function to make it easier
    if it can be integrated into carbon fields it would be great

    function carbon_get_the_term_meta( $taxonomy = 'category', $field_name ) {
    	$term = get_query_var( $taxonomy );
    	$term = get_term_by( 'slug', $term, $taxonomy );
    	return carbon_get_term_meta( $term->term_id, $field_name );
    }
    Plugin Author htmlBurger

    (@htmlburger)

    Hi @alexadark,

    Here is a simpler solution to fetch the meta value for the currently queried term:

    carbon_get_term_meta( get_queried_object_id(), 'crb_hero_tax_image' );

    Function Reference: get_queried_object_id()

    • This reply was modified 8 years, 1 month ago by htmlBurger.
    Thread Starter alexadark

    (@alexadark)

    Great!
    Thank you
    you should have this type of things in the doc, it would be super usefull

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘term_meta custom fields’ is closed to new replies.