Getting some issues with taxonomy images plugin.I am trying to limit the number of taxonomy terms displayed on a page to 6. The following code is what I'm working with. It shows the term name and image attachment. Tips on how to limit the number of terms/images?

$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
            'taxonomy' => 'technologies',
        ) );
        if ( ! empty( $terms ) ) {
            print "\n" . '<div class="row">';
            foreach( (array) $terms as $term ) {
                print "\n" . '<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6">';
                print "\n\t" . wp_get_attachment_image($term->image_id, array('600', '600'), "", array("class" => "img-responsive tech-logo" )  ); 
                print "\n\t" . '<h6 class="tech-description text-center">' . esc_html( $term->name ) . '</h6>';
                print "\n" . '<span class="hidden-lg hidden-md"><br/><br/></span></div>';
            print "\n" . '</div>';

The filter uses the third parameter as an array that gets passed to get_terms(), which you're already using to specify the taxonomy to query. Looking at the get_terms() documentation, you can see there's a 'number' argument that you can pass to limit the number of terms returned. This is what you want to use.

Your use of the filter now becomes

$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    'taxonomy'  => 'technologies',
    'term_args' => array(
        'number' => 6,
) );

When the filter is applied, $terms should now be limited to a max of 6 terms.


The plugin is using a deprecated argument for get_terms(), which pre-4.5 took two parameters: the taxonomy string and an array of options. That options array is defined as $term_args in the plugin. As long as that's in there, you'll need to pass an array with 'taxonomy', and 'term_args[]' passed separately instead of in the same array as get_terms() expects them to be after WP 4.5.

  • Hi @morganestes, thanks for your reply. I also looked at this and thought it would have been a solution, but it doesn't seem to be working for some reason. Further thoughts? – streetfire Jun 12 '17 at 20:51
  • The plugin you're using is passing arguments to get_terms() using a deprecated argument. Until that is fixed, you need to pass your args as part of the 'term_args' array key. I've updated my code to reflect the change needed. – Morgan Estes Jun 12 '17 at 23:51
  • Well, that did limit it to 6, however the update no longer shows just the terms applying to the post. It shows 6 terms, all the same, alphabetically. – streetfire Jun 13 '17 at 0:40
  • I think for that you need to contact their support team wordpress.org/support/plugin/taxonomy-images – Morgan Estes Jun 13 '17 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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