List titles of all custom post types

The code below is from a post by MichaelH on the WP Support forum:

//get all custom post types, if publicly_queryable,
//display all published article titles for each of those types
$args=array(
  '_builtin' => false,
);
$output = 'objects'; // names or objects
$post_types=get_post_types($args,$output);
foreach ($post_types  as $post_type ) {
  if (true == $post_type->publicly_queryable) {
    $type = $post_type->name;
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of ' . $post_type->label;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a title="Permanent Link to <?php the_title_attribute(); ?>" rel="bookmark" href="<?php the_permalink() ?>"></a>

              endwhile;
    }
    wp_reset_query();
  }
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

*