简体   繁体   中英

How to display custom taxonomy fields into category loop?

I have that code in my category.php which enables list subcategories

<?php $categories = get_categories(array('child_of' => 7)); ?>
<?php foreach ($categories as $child) { ?>
//do stuff
<?php } ?>

For categories I've created custom text field with name = text. And now I want to show that custom field inside this loop. Can you help me please? I've tryed

<?php $categories = get_categories(array('child_of' => 3)); ?>
<?php foreach ($categories as $child) { ?>
<h2><?php echo $child->cat_name; ?></h2>
<p> <?php echo $child->category_description; ?> </p>
<p><?php echo get_field( 'text', $term->taxonomy . '_' . $term->term_id ); ?></p>
<?php } ?>

This code show Cat name, cat description but no custom field.. Help me please to do that.

<?php $categories = get_categories(array('child_of' => 3)); ?>
<?php foreach ($categories as $child) { ?>
<h2><?php echo $child->cat_name; ?></h2>
<p> <?php echo $child->category_description; ?> </p>
<p><?php echo get_field( 'text', $child->taxonomy . '_' . $child->term_id ); ?>           </p>
<?php } ?>

You used $term instead od $child

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM