Support

Account

Home Forums Front-end Issues How to get field from from taxonomy of CPT?

Unread

How to get field from from taxonomy of CPT?

  • Hello. I have CPT – “Catalog”, and my CTP have custom taxonomy Type.
    I try to display all categories on another page and I’m used this code:

    <?php
    																		$categories = get_categories(array(
    																			'taxonomy' => 'type',
    																			'type' => 'catalog',
    																			'orderby' => 'name',
    																			'hide_empty'   => 0,
    																			'order' => 'ASC'
    																		));
    																		foreach( $categories as $category ){
    																			echo '<div class="col-12 col-md-6 col-lg-4">';
    																			echo '<div class="n-catalog-item__block">';
    																			echo '<a href="' . get_category_link( $category->term_id ) . '" class="n-catalog-item__icon"><img src="' . get_field('catalog_category_icon', $category->term_id) . '"></a>';
    																			echo '<div class="n-catalog-item__info">';
    																			echo '<div class="n-catalog-item__name"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "Усі матеріали в категорії: %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </div> ';
    																			echo '</div>';
    																			echo '</div>';
    																			echo '</div>';
    																		}
    																	?>

    In this code I try to display my custom field:
    <img src="' . get_field('catalog_category_icon', $category->term_id) . '">

    If I do <?php var_dump($category->term_id); ?> – return “int(402)” – (402 its category ID)

    What I do wrong?

Viewing 1 post (of 1 total)

The topic ‘How to get field from from taxonomy of CPT?’ is closed to new replies.