Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've searched this site and tried all kinds of ways to exclude categories 1 and 7 from this list, but nothing is working. No errors but doesn't hide the cats either.

Categories 1 and 7 are not empty, but I'd also like to exclude empty categories, so !empty must stay.

<!-- category list with thumbs -->
<?php
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'category') );

if ( ! empty( $terms ) ) {

  foreach( (array) $terms as $term ) {
      echo '<div class="issue clear"><h3><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a></h3>';
      echo '<div class="grid col-120 hide"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '"><img src="IMG SRC" alt="" /></a></div>';
      echo '<div class="grid col-780 fit">'. $term->description . '</div></div>';
  }

}
?>
share|improve this question
    
Is this a plugin? You may need to contact them, I'm not sure how their filter works. That being said, the non-ideal way would be to add an if statement in your foreach if($term->term_id != 7 || $term->term_id != 8) - alternatively you could put the ids in an array and use something like !in_array() –  Howdy_McGee Mar 19 at 15:40
    
Yes, it's a plugin: Taxonomy Images. Thanks, I've tried excluding term IDs like that, and in a zillion other ways. Feel like pulling my hair at this point. –  Phantasmix Mar 19 at 15:48

1 Answer 1

You could try modifying your query such that you have an array of categories to exclude and a conditional in the foreach, working similarly to the !empty(). An untested example:

<!-- category list with thumbs -->
<?php
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'category') );
$exclude = array(1,7); //add the category IDs to exlcude here

if ( ! empty( $terms ) ) {

  foreach( (array) $terms as $term ) {

        //check the category's ID and output code
        //if it's not in the $exclude array
        if ( ! in_array($term->term_id, $exclude) ) {
            echo '<div class="issue clear"><h3><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a></h3>';
            echo '<div class="grid col-120 hide"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '"><img src="IMG SRC" alt="" /></a></div>';
            echo '<div class="grid col-780 fit">'. $term->description . '</div></div>';
        }//if in_array

    }//for each

}//if empty
?>
share|improve this answer
    
i've tried this, it didn't work for whatever reason. I should've mentioned that I was working with a Multisite setup, and the plugin is only compatible up to WP 3.6. I removed the plugin and rewrote the function completely, relying only on WP basics and Advanced Custom Fields. -- Thanks for giving it a shot. –  Phantasmix Mar 19 at 19:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.