Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Sitemap with Custom Post Types ExampleFrom the blog post: http://davidakennedy.com/2011/sitemap-with-custom-post-types/
<h2 id="my-post-type">My Post Type</h2>
<ul>
<?php
$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(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$new = new WP_Query($args);
while ( $new->have_posts() ) {
$new->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
echo '</ul>';
echo '</li>';
} ?>
</ul>
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.