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:
- Top Level 1
- Second Level Term 1
<div>WYSIWYG Field</div>
- Top Level 2
<div>WYSIWYG Field</div>
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>