Display Custom Post Types in WordPress Category

By default the Category Archive Query doesn’t take into account Custom Post Types. It takes into consideration only posts.

To change that you’ll need to use some custom code. Add the code below in your functions.php file or inside a new plugin:

1. Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db

2. Add the following code to the end of it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * Display Custom Post Types in WordPress Category
 * @param WP_Query $query
 * @return WP_Query
 */
 
function wckc_add_my_custom_post_type ($query) {
    if(
        empty($query->query['post_type'])
        or $query->query['post_type'] === 'post'
    ){
        $query->set('post_type', array('post', 'page', 'add_your_custom_post_type'));
    }
}
 
add_action('pre_get_posts', 'wckc_add_my_custom_post_type');

3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality

If you want to create your own Archive use:

1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Display Custom Post Types in WordPress Category
 */
 
$args = array( 'post_type' => 'add_your_custom_post_type', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
	the_title();
	echo '<div class="entry-content">';
	the_content();
	echo '</div>';
endwhile;