S
S
serega 20702018-11-23 16:09:43
Themes
serega 2070, 2018-11-23 16:09:43

How to display the category name of the created taxonomy in the template?

Hi guys! previously not associated with arbitrary fields, namely the ACF plugin, please tell me how to display the Category Name of the created Taxonomy in the template, I display them using

$thiscat = get_queried_object();
$thiscat_id = $thiscat->term_id;
$posts = get_field('list', 'category_' . $thiscat_id);
 if( $posts ): ?>
foreach( $posts as $p )
 $name_id = get_field('name_id', $p->ID);

название:<?php echo $name; ?>

and in the name: it displays category IDs (I can’t figure out where to dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yanchevsky, 2018-11-23
@deniscopro

Like this?
<?php single_cat_title(); ?>

A
Alexander Pushkarev, 2018-11-23
@AXP-dev

<?php
/**
 * @var $thiscat WP_Term
 * @var $posts WP_Post[]
 */
$thiscat = get_queried_object();

if ($posts = get_field('list', $thiscat)) {
    foreach ($posts as $post) {
        $name_id = get_field('name_id', $post);
        $terms = get_the_terms($post, $thiscat->taxonomy); // массив всех категорий поста
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question