Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress Sitemap with Custom Post Types ExampleFrom the blog post:
<h2 id="my-post-type">My Post Type</h2>
$terms = get_terms( 'my_taxonomy', 'orderby=name' );
foreach ( $terms as $term ) {
echo '<li><h3>' . $term->name . '</h3>';
echo '<ul>';
$args = array(
'post_type' => 'my_post_type',
'posts_per_page' => -1,
'tax_query' => array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => $term->slug
$new = new WP_Query($args);
while ( $new->have_posts() ) {
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
echo '</ul>';
echo '</li>';
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.