Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

category archive for custom post type not functioning properly WordPress

  • SOLVED

I have a custom post type created that uses 'category' . I did not not set up a custom taxonomy, just using categories.

When I view my site at /category/category-name it is display all posts from the custom post type instead of just posts from that category.

Here are the contents of category.php


<?php query_posts('post_type=portfolio'); if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_content(); ?>
</article><!-- end post-->
<?php endwhile; ?>
<?php endif; ?>



Here is the code from functions.php to create the custom post type.


add_action( 'init', 'register_cpt_portfolio' );

function register_cpt_portfolio() {

$labels = array(
'name' => _x( 'Portfolio', 'portfolio' ),
'singular_name' => _x( 'Portfolio', 'portfolio' ),
'add_new' => _x( 'Add New', 'portfolio' ),
'add_new_item' => _x( 'Add New Portfolio', 'portfolio' ),
'edit_item' => _x( 'Edit Portfolio', 'portfolio' ),
'new_item' => _x( 'New Portfolio', 'portfolio' ),
'view_item' => _x( 'View Portfolio', 'portfolio' ),
'search_items' => _x( 'Search Portfolio', 'portfolio' ),
'not_found' => _x( 'No portfolio found', 'portfolio' ),
'not_found_in_trash' => _x( 'No portfolio found in Trash', 'portfolio' ),
'parent_item_colon' => _x( 'Parent Portfolio:', 'portfolio' ),
'menu_name' => _x( 'Portfolio', 'portfolio' ),
);

$args = array(
'labels' => $labels,
'hierarchical' => false,

'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
'taxonomies' => array( 'category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,


'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);

register_post_type( 'portfolio', $args );
}



What do I need to do in order to only show posts that belong to the category?

Answers (1)

2012-06-25

Arnav Joy answers:

try this


<?php $catID = get_query_var('cat');query_posts('cat='.$catID.'&post_type=portfolio'); if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php the_content(); ?>

</article><!-- end post-->

<?php endwhile; ?>

<?php endif; ?>


Dan | gteh comments:

thanks, that seems to have done it, just checking to see if it works properly everywhere.