Site logo

Archived topic

Display All Terms of Taxonomy

5 replies · Started by John on January 10, 2023

Viewing posts 1–6 of 6

Hi,

I have a provider post type, with a type of services taxonomy.

I'm able to use GP/GB to create a loop showing each provider and show the list of terms for each provider. However, I have a lot of Providers and a more manageable number of Types of Services - obviously, the point of a taxonomy is to group items meaningfully together.

So I don't want to display the list of all Providers, instead I want to show the list of Services, each directing to a page where the Providers for that type of services are displayed.

Problem is, as obvious as the use case seems, I can't find a way with GP or GB to simply show a list of taxonomy terms. Is it possible?

Thank you

Hi John,

It's possible but doing it dynamically will require custom code.

Do you have a lot of terms for this custom taxonomy? If not, what I would suggest is to build the list from scratch so you can properly design it with GenerateBlocks.

If you have a lot, you can a shortcode to query them but you'll need custom CSS to style this.

Sample Shortcode:

add_shortcode( 'my_shortcode', function() {
    ob_start();
    // Start your PHP below
  
    $terms = get_terms(
    array(
        'taxonomy'   => 'your-taxonomy',
        'hide_empty' => false,
    )
);

// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
    // Run a loop and print them all
    foreach ( $terms as $term ) { ?>
        <a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
            <?php echo $term->name; ?>
        </a><?php
    }
} 
  
    // End your PHP above
    return ob_get_clean();
} );

Replace your-taxonomy with your taxonomy slug.

Creating it through GenerateBlocks manually would be an easier approach design-wise.

Thanks Fernando. I was indeed hoping to get the best of both worlds: generate the list dynamically and style it with GenerateBlocks, similarly to a GB Query Loop. I do need to design it, include the term description, etc.

I don't have many terms right now, but this will change so I wanted to avoid doing it manually as much as possible. But the shortcode option doesn't really suit me, so I will have to go with manual...

Is there any plan to include this feature in GB (Pro) going forward? I was hoping that when defining a Query Loop, I would simply choose "Taxonomy" instead of "Post" type.

Ok thank you. Too bad, that'd be very useful. I submitted a feature request.

You're welcome, John!

This archived topic is closed to new replies.