Home › Forums › Front-end Issues › Fields for custom taxonomy not showing
Hi,
I’m having trouble to show some acf fields used for custom taxonomies, I read the documentation but it doesn’t seem to be working.
<div id="content" class="tm-content tm-food-menu primary c12 columns" role="main">
<header class="page-header">
<h1 class="page-title delta small-title"><?php the_title(); ?></h1>
</header>
<?php
$t_args = array( 'taxonomy' => 'course_cat', 'hide_empty' => 0, 'parent' => 0 );
$t_items = get_categories( $t_args );
foreach ( $t_items as $t_item ) :
$menu_footer = get_field( 'menu_footer', $t_item->slug );
?>
<section id="<?php echo $t_item->slug; ?>" class="wrapper">
<h2 class="entry-title alpha c12 columns"><?php echo $t_item->name; ?></h2>
<?php the_field( 'menu_footer', $t_item->slug ); ?>
<footer class="entry-footer c12 columns">
<?php echo $menu_footer; ?>
<?php if ( get_field( 'menu_add1' ) ) : ?>
<div class="entry-extra entry-extra-1 row">
<div class="item-extra c9 columns"><?php the_field( 'menu_add1' ); ?></div>
<?php if ( get_field( 'menu_ap1' ) ) : ?>
<div class="item-price c3 columns end">
<?php
$item_price_ap = get_field( 'menu_ap1' );
echo '$ ' . number_format( $item_price_ap, 2, '.', ',' );
?>
</div>
<?php endif; ?>
</div>
<!-- end .entry-extra-1 -->
<?php endif; // end menu_add1 ?>
</footer>
<article class="entry-dish c12 columns">
<?php
$args = array(
'post_type' => 'course_items',
'tax_query' => array(
array(
'taxonomy' => 'course_cat',
'field' => 'slug',
'terms' => $t_item->slug,
),
),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
?>
<?php get_template_part( 'partials/content', 'courseitems' ); ?>
<?php endwhile; wp_reset_postdata(); ?>
</article>
</section>
<?php endforeach; ?>
</div>
I thought that maybe the wp_reset_postdata() tag was the problem, but I moved it around and didn’t seem to work.
This code is used inside a page template, everything else works, even the acf fields in the content_courseitems.php called with the get_template_part().
I just can’t seem to be able to get the taxonomy fields :/
Old questions and I assume that you’ve either figured this out or moved on by now, but for anyone else that’s looking for the same information please see the “Get a value from other places” section of this page https://www.advancedcustomfields.com/resources/get_field/
Specifically for the OP the following code
foreach ( $t_items as $t_item ) :
$menu_footer = get_field( 'menu_footer', $t_item->slug );
should look like
foreach ( $t_items as $t_item ) :
$menu_footer = get_field( 'menu_footer', $t_item->taxonomy.'_'.$t_item->term_id );
The topic ‘Fields for custom taxonomy not showing’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.