• I need to show all posts in all categories (custom post type)? Below code works with normal post only, but I think it can be change to works with custom post type. Can you give me an example? Thank you.

    Output look like this:

    custom post type cat 1
    + post a
    + post b
    custom post type cat 2
    + post c
    + … etc

    <?php
            //for each category, show all posts
            $cat_args=array(
              'orderby' => 'name',
              'order' => 'ASC',
               );
            $categories=wp_list_categories($cat_args);
              foreach($categories as $category) {
                $args=array(
                  'showposts' => -1,
                  'category__in' => array($category->term_id),
                  'caller_get_posts'=>1
                );
                $posts=get_posts($args);
                  if ($posts) {
                    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
                    foreach($posts as $post) {
                      setup_postdata($post); ?>
    
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
      <?php the_title(); ?>
      </a></p>
        <?php
                    } // foreach($posts
                  } // if ($posts
                } // foreach($categories
            ?>
  • The topic ‘How to show all posts in all categories custom post type?’ is closed to new replies.