Organize posts under custom category in WordPress

I’ve been working on this for two straight days and I can’t for the life of me figure this thing out.

I have a custom post type ‘teams’ that has custom categories assigned to it called ‘boys division’ and I’m trying to add code to my template that would display all the posts assigned to this custom category.

Read More

For example, I’d like to have it displayed like this:

Boys U10

Panthers

Cobras

Aztecs

Boys U12

Stars

Kings

Ducks

Cosmos

Any help would be greatly appreciated. I’ve tried Googling this 100 times and nothing seems to work. Here’s what I have…

<?php
    //for each category, show posts
    $cat_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'orderby' => 'title',
          'order' => 'ASC',
          '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
            } 
          } 
        } 
    ?>

Related posts

Leave a Reply

1 comment

  1. You stated that the code you have provided works but selects categories from the wrong taxonomy. In that case, all you need to do is change the taxonomy from which you select categories, which can be done by adding the parameter “taxonomy” in $cat_args.

    $cat_args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'taxonomy' => 'teams_taxonomy'
    );
    

    I don’t know what your taxonomy is called. But you have registered it somewhere so you can look it up, the function you used to register the taxonomy for teams is register_taxonomy.