---
title: Display posts of custom post type hierarchically by custom taxonomy
url: "https://www.seopress.org/support/hooks/display-posts-of-custom-post-type-hierarchically-by-custom-taxonomy/"
lang: en-US
updated: 2023-08-23
hook_name: seopress_sitemaps_html_hierarchical_terms_query, seopress_sitemaps_html_hierarchical_tax_query
required_version: 7.0
---

# Display posts of custom post type hierarchically by custom taxonomy

- **Hook name:** `seopress_sitemaps_html_hierarchical_terms_query, seopress_sitemaps_html_hierarchical_tax_query`
- **Required version:** 7.0

```php
add_filter('seopress_sitemaps_html_hierarchical_terms_query', 'sp_sitemaps_html_hierarchical_terms_query', 10, 2);
function sp_sitemaps_html_hierarchical_terms_query($cpt_key, $args_terms_query) {
    if ($cpt_key === 'testimonials') {//replace 'testimonials' with your own post type key
        $cats = get_terms('type', $args_terms_query);
        return $cats;
    }
    return;
}

add_filter('seopress_sitemaps_html_hierarchical_tax_query', 'sp_sitemaps_html_hierarchical_tax_query', 10, 3);
function sp_sitemaps_html_hierarchical_tax_query($cpt_key, $term, $args) {
    if ($cpt_key === 'testimonials') {//replace 'testimonials' with your own post type key
        unset($args['tax_query']);
        $args['tax_query'] = [[
            'taxonomy' => 'type', //replace 'type' with your own custom taxonomy key
            'field'    => 'term_id',
            'terms'    => $term->term_id,
        ]];
        return $args;
    }

    return;
}
```

Source: [https://gist.github.com/wp-seopress/52744c742365941b89f35153b9f270e2](https://gist.github.com/wp-seopress/52744c742365941b89f35153b9f270e2)



