Skip to content

Instantly share code, notes, and snippets.

@bhubbard
Created March 9, 2015 17:25
Show Gist options
  • Save bhubbard/62feb556e3806d56cb2d to your computer and use it in GitHub Desktop.
Save bhubbard/62feb556e3806d56cb2d to your computer and use it in GitHub Desktop.
Wordpress loop of all custom post types and posts
/*
Loop thru all Custom Post Types
foreach( get_post_types( array('public' => true) ) as $post_type ) {
if ( in_array( $post_type, array('post','page','attachment') ) )
continue;
$pt = get_post_type_object( $post_type );
echo '<div class="row sitemap-section"> <div class="col-sm-12">';
echo '<h4>'.$pt->labels->name.'</h4>';
echo '<ul>';
query_posts('post_type='.$post_type.'&posts_per_page=-1');
while( have_posts() ) {
the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
echo '</ul>';
echo '</div></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment