Home Forums Front-end Issues get_terms If Have Any Content in WYSIWYG Field


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:

    • 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;
    	} ?>
  • 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!

        <?php $hiterms = get_terms("foxyshop_categories", array("orderby" => "menu_order", "parent" => 0)); ?>
        <?php foreach($hiterms as $key => $hiterm) : ?>
                <?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) : ?>
                        <?php foreach($loterms as $key => $loterm) : ?>
    	                        <?php echo $loterm->name; ?>
    	                        <?php if (get_field('category_bare_care', $loterm)) :
    					            the_field('category_bare_care', $loterm);
    				            endif; ?>
                        <?php endforeach; ?>
                <?php endif; ?>
        <?php endforeach; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.