Make category list custom post types – WordPress

The archive.php only list the post type "post" but you can change that with this simple snippet.

If you want to make your archive.php to list your own custom post types paste the following code into your functions.php
Then, the category and tag lists will also print the post types.

Add your own "your-custom-post-type" to the array list:

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'your-custom-post-type'
		));
	  return $query;
	}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*