Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-seopress/52744c742365941b89f35153b9f270e2 to your computer and use it in GitHub Desktop.
Save wp-seopress/52744c742365941b89f35153b9f270e2 to your computer and use it in GitHub Desktop.
Display posts of custom post type hierarchically by custom taxonomy
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