Support » Themes and Templates » Displaying all categories and posts of a certain custom post type

  • Resolved carbonmadex


    Hello guys,

    I’m new to custom post types and don’t know how to display all of the contents of a certain custom post type in a page.

    For example if I have a custom post type named “portfolio”, and if there are categories under it named “x”, “y”, “z”. I want to have a page like this:



    * x-post1
    * x-post2


    * y-post1
    * y-post2


    * z-post1
    * z-post2

    Trying to make it so whatever “categories” get created will show.
    I would appreciate any help. Thanks in advance.

Viewing 1 replies (of 1 total)
  • This should do it

    List all posts sorted by tag name or category name or taxonomy custom taxonomy
    Within each category posts sorted ascending by post title.

    //get all terms (e.g. categories or post tags), then display all posts in each term
    $taxonomy = 'category';//  e.g. post_tag, category
    $param_type = 'category__in'; //  e.g. tag__in, category__in
      'include' => '1,2,3',
      'orderby' => 'name',
      'order' => 'ASC',
      'child_of' => 3
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
          "$param_type" => array($term->term_id),
          'order' => 'ASC',
          'orderby' => 'title',
          'post_type' => 'portfolio',
          '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 Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    wp_reset_query();  // Restore global post data stomped by the_post().

Viewing 1 replies (of 1 total)
  • The topic ‘Displaying all categories and posts of a certain custom post type’ is closed to new replies.