[Closed] custom post list doesn't appear in a category-slug.php file.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by bruce 8 years ago.

Assigned support staff: bruce.


I created a custom post type like house

Custom post type name plural (required): houses

Custom post type name singular (required): house

Slug (required): house


Make this type public :check

Select Taxonomies

Rewrite : true
Use the normal WordPress URL logic : check

Allow permalinks to be prepended with front base: true

Feeds: true

Pages: true

has_archive: true

show_in_menu: true

show_ui: true

publicly_queryable: ture

exclude_from_search: false

hierarchical: false




Permalink epmask

) and generated view templates.

What I want is to display house category in the "category-house.php" file. (My theme is twentyeleven.)

I added a category like house and duplicated category.php and renamed it as category-house.php.

And when I published custom posts, I assigned them to the category house.

But when I address hidden link, it doesn't show any post but shows "Apologies, but no results were found ......"

Please help me to display custom post list in a category-slug.php file.



Languages: English (English )

Timezone: Australia/Perth (GMT+08:00)

Hi David,

WordPress doesn't do this by default and you'll need to add a filter hook to your theme functions.php file.

Something like this:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

	if ( is_post_type_archive() && $query->is_main_query() ) {
		$query->set( 'post_type', array( 'post', 'house' ) );

	return $query;

Best regards,


I added the code above to the functions.php but nothing happened.

So I added the code below in the category-house.php file.

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?> 
  $type = 'house';
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    'post_type' => $type,
    'post_status' => 'publish',
    'paged' => $paged,
    'is_category' => 1,
    'category_name' => $term->slug,
    'posts_per_page' => 8,
  $temp = $wp_query;
  $wp_query = null;
  $wp_query = new WP_Query();

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) {

	wp_pagenavi(array( 'query' => $wp_query )); 

} ?>

It shows the post and pagenavi but when I click the second page(/page/2/), it goes to 404 error page.

Do you have any idea?



Languages: English (English )

Timezone: Australia/Perth (GMT+08:00)

Hi David,

If you do it that way then you have to handle pagination yourself.

Try this in your functions.php

add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_archive() ) {
/* Taxonomy archives. */
if ( is_tax() || is_category() || is_tag() ) {
$query->set( 'post_type', array( 'post', 'house' ) );

return $query;

Best regards,

The topic ‘[Closed] custom post list doesn't appear in a category-slug.php file.’ is closed to new replies.