Home › Forums › Front-end Issues › get_terms If Have Any Content in WYSIWYG Field
Is it possible to display a hierarchal list of terms only if the term has any content in a WYSIWYG field? I’ve been Googling all morning but am not finding any info on get_terms that don’t involve posts.
Desired Output:
The attempt below is displaying all terms but they’re not hierarchal and I can’t figure out how to output the_field.
<ul class="plant-care-list no-bullet-list">
<?php // Foxyshop Categories
$terms = get_terms('foxyshop_categories', array(
'orderby' => 'menu_order',
'order' => 'DESC',
'hide_empty' => 0,
'exclude' => array(9,9999),
));
foreach( $terms as $term ) {
//if (get_field('category_bare_care')) {
$category_html = '<li><h3>' . $term->name . '</h3></li>';
echo $category_html;
//}
} ?>
</ul><!--plant-care-list-->
Actually, I think I solved this finally using part of a snippet I found pages deep on my Google search. I also didn’t realize I needed to specify which category to get the field data from even though I’m inside a foreach statement. get_field(‘category_bare_care’, $hiterm) is working fine. Hope this helps someone else!
<ul>
<?php $hiterms = get_terms("foxyshop_categories", array("orderby" => "menu_order", "parent" => 0)); ?>
<?php foreach($hiterms as $key => $hiterm) : ?>
<li>
<?php echo $hiterm->name; ?>
<?php if (get_field('category_bare_care', $hiterm)) :
the_field('category_bare_care', $hiterm);
endif; ?>
<?php $loterms = get_terms("foxyshop_categories", array("orderby" => "menu_order", "parent" => $hiterm->term_id)); ?>
<?php if($loterms) : ?>
<ul>
<?php foreach($loterms as $key => $loterm) : ?>
<li>
<?php echo $loterm->name; ?>
<?php if (get_field('category_bare_care', $loterm)) :
the_field('category_bare_care', $loterm);
endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
You must be logged in to reply to this topic.
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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.