Skip to main content
Made the post less specific to help others with a simialr problem understand it more
Source Link
Randomer11
  • 416
  • 11
  • 31

I've been looking at this old theme, which has an "events" post type. I've added a custom taxonomy "eventcat". I'veI've then created a template file called taxonomy-eventcat.php which is where im now stuck template file and post types. When querying to show only the posts in the category selected. This is the top of my template :

<?php if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

    $args=array ( 
    
            'post_type'=> array( 'events' ),
            'tax_query' => array(  'taxonomy' => 'eventcat''tax-cat' ), 
            'post_status' => array( 'future' ), 
            'pagination' => true, 
            'paged' => $paged,
            'orderby' => 'post_date',
            'order' => 'ASC', ); 
    $temp = $wp_query; 
    
    $wp_query = null; 
    $wp_query = new WP_Query(); 
    $wp_query->query( $args ); 
 
if ( $wp_query->have_posts() ) { while ( $wp_query->have_posts() ) { $wp_query->the_post();
?>

Which ive taken from the existing page template, but the above seems to show ALL Posts in the custom post type, rather than just the posts in the category.

Could someone please provide a correct query and explain why it works/doesnt work so I understand in the future.

Thank you very much for any help.

I've been looking at this old theme, which has an "events" post type. I've added a custom taxonomy "eventcat". I've then created a template file called taxonomy-eventcat.php which is where im now stuck. When querying to show only the posts in the category selected. This is the top of my template :

<?php if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

    $args=array ( 
    
            'post_type'=> array( 'events' ),
            'tax_query' => array(  'taxonomy' => 'eventcat' ), 
            'post_status' => array( 'future' ), 
            'pagination' => true, 
            'paged' => $paged,
            'orderby' => 'post_date',
            'order' => 'ASC', ); 
    $temp = $wp_query; 
    
    $wp_query = null; 
    $wp_query = new WP_Query(); 
    $wp_query->query( $args ); 
 
if ( $wp_query->have_posts() ) { while ( $wp_query->have_posts() ) { $wp_query->the_post();
?>

Which ive taken from the existing page template, but the above seems to show ALL Posts in the custom post type, rather than just the posts in the category.

Could someone please provide a correct query and explain why it works/doesnt work so I understand in the future.

Thank you very much for any help.

I've been looking at this old theme. I've then created a template file called taxonomy template file and post types. When querying to show only the posts in the category selected. This is the top of my template :

    $args=array ( 
    
            'post_type'=> array( 'events' ),
            'tax_query' => array(  'taxonomy' => 'tax-cat' ), 
            'post_status' => array( 'future' ), 
            'pagination' => true, 
            'paged' => $paged,
            'orderby' => 'post_date',
            'order' => 'ASC', ); 
    $temp = $wp_query; 
    
    $wp_query = null; 
    $wp_query = new WP_Query(); 
    $wp_query->query( $args ); 

Which ive taken from the existing page template, but the above seems to show ALL Posts in the custom post type, rather than just the posts in the category.

Source Link
Randomer11
  • 416
  • 11
  • 31

Custom post type Category Display

I've been looking at this old theme, which has an "events" post type. I've added a custom taxonomy "eventcat". I've then created a template file called taxonomy-eventcat.php which is where im now stuck. When querying to show only the posts in the category selected. This is the top of my template :

<?php if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

    $args=array ( 
    
            'post_type'=> array( 'events' ),
            'tax_query' => array(  'taxonomy' => 'eventcat' ), 
            'post_status' => array( 'future' ), 
            'pagination' => true, 
            'paged' => $paged,
            'orderby' => 'post_date',
            'order' => 'ASC', ); 
    $temp = $wp_query; 
    
    $wp_query = null; 
    $wp_query = new WP_Query(); 
    $wp_query->query( $args ); 

if ( $wp_query->have_posts() ) { while ( $wp_query->have_posts() ) { $wp_query->the_post();
?>

Which ive taken from the existing page template, but the above seems to show ALL Posts in the custom post type, rather than just the posts in the category.

Could someone please provide a correct query and explain why it works/doesnt work so I understand in the future.

Thank you very much for any help.