Last active
August 23, 2023 13:16
-
-
Save wp-seopress/52744c742365941b89f35153b9f270e2 to your computer and use it in GitHub Desktop.
Display posts of custom post type hierarchically by custom taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment