Forums

Taxonomy Images
[resolved] Having_images set to false not working (7 posts)

  1. miruru
    Member
    Posted 12 months ago #

    When using the option: 'having_images'=>false, this does not return all the terms that has an image associated with it. It only displays the terms that has posts with the images. Is this the normal behaviour?

    For example, I have 20 terms, each with an image, 10 of these terms has a number of posts. I want to be able to display all 20 terms in a given taxonomy whether or not they have any posts. Is this possible?

  2. Diogo15
    Member
    Posted 12 months ago #

    hide_empty = 0

  3. Michael Fields
    Theme Wrangler
    Posted 12 months ago #

    Setting having_images to false will just return unfiltered output of get_terms(). Please try Diogo15's suggestion of setting the hide_empty argument of get_terms(). This would look something like this:

    $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    	'taxonmoy'  => 'taxonomy-name',
    	'term_args' => array(
    		'hide_empty' => 0,
    		),
    	) );
  4. miruru
    Member
    Posted 12 months ago #

    Thank you Diogo15 and Michael, using hide_empty worked.

  5. wyndot
    Member
    Posted 10 months ago #

    I'm trying to use this and it's not working for me. Here's my code:

    <?php $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
        'taxonomy' => 'tool',
        'term_args' => array(
    		'hide_empty' => 0,
    		),
        ) );
    
    		if ( ! empty( $terms ) ) {
        	print '<ul class="taxonomy">';
        	foreach( (array) $terms as $term ) {
            	print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . esc_html( $term->name ) . '</a></li>';
        	}
        	print '</ul>';
    	}
    ?>

    It displays the image and term name fine if there is an image, but i still want the term name to display if there is no image associated with it.

    Thanks for the plugin!

  6. Michael Fields
    Theme Wrangler
    Posted 10 months ago #

    You'll need to set "having_images" to false in the filter's array.

  7. wyndot
    Member
    Posted 10 months ago #

    Thanks, sorry to bother you with that. I tried having_images earlier and I now realize that I was typing it I kept typing quotes around false when I shouldn't have. I guess that's what happens when you're working way too late :)

Reply

You must log in to post.

About this Plugin

About this Topic