2

I have created both a Custom Post Type (Match) and Custom Taxonomy (Team), and have made the Team taxonomy available to normal posts (news for that team) and the Match custom post type.

However, on the Archive template page I have created taxonomy-team.php, the posts are not separating into a News section and a Match section.

I have tried various solutions, but both are currently showing the same content - all posts and all matches for the Team.

I have restored the second section "Matches" to show the two ways I have tried from reading answers here and on various tutorial sites.

<?php
/**
 * The template for displaying Archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package aThemes
 */

get_header(); ?>

    <section id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

<?php
    // This sets out a variable called $term - we'll use it ALOT for what we're about to do.
     $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

<!-- See how we used the variable to let Wordpress know we want to display the title of the taxonomy? -->
    <div id="matchheader"><?php echo $term->name; ?></div>

<!-- Using the same variable, we can use it to display the posts that the artist has been tagged in -->
    <h2><?php echo $term->name; ?> News</h2>
    <ul class="newslist">
<?php $args = array(
    'post_type'                => 'match',
    'child_of'                 => 0,
    'parent'                   => '',
    'orderby'                  => 'name',
    'order'                    => 'ASC',
    'hide_empty'               => 1,
    'hierarchical'             => 1,
    'exclude'                  => '',
    'include'                  => '',
    'number'                   => '',
    'taxonomy'                 => 'team',
    'pad_counts'               => false 

    ); 
$categories = get_categories( $args );
foreach ( $categories as $cat ) {

$posts_array = get_posts(
    array(
        'posts_per_page' => -1,
        'post_type' => 'match',
        'tax_query' => array(
            array(
                'taxonomy' => 'team',
                'field' => 'term_id',
                'terms' => $cat->term_id,
            )
        )
    )
); }
?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> -  <?php the_time('d M Y'); ?></li>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    </ul>

    <h2><?php echo $term->name; ?> Matches</h2>
    <ul class="matchlist">
    <?php while (have_posts()) : the_post(); ?>       
                <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> -  <?php the_time('d M Y'); ?></li>
    <?php endwhile; ?>
    </ul>

            </div><!-- #content -->
    </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>    

How can I separate the archive pages so they show the News and Matches for each Team separately?

1

Going from memory this should work for posts

<?php $query1 = new WP_Query( array( "post_type" => "post", "tag" =>
$term->slug) ); ?>

The first query will only return posts that have been tagged [TEAMNAME] (as far as I can remember custom taxonomies can show up as tags on a post). This should work for teams

<?php $query2 = new WP_Query( array( "post_type" => "match", "team" => $term->slug) ); ?>

The second query will only returns matches with the custom taxonomy of [TEAMNAME]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.