Support » Fixing WordPress » Custom Post Type on home.

  • Darrenmooney



    I’m using the following code to display all custom post types on the home page of a site.

    add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
    function add_my_post_types_to_query( $query ) {
      	if ( is_home() && $query->is_main_query() )
      		  $query->set( 'post_type', array( 'post', 'videos', 'podcast' ) );
      	return $query;

    I have all post types sharing post tags, however when clicking a tag on a post, only regular posts show. I had added “|| is_tag()” after “is_home()”, however this resulted in my archive-blog.php page (which is setup to only show blog posts) showing all post types just like the home page.

    I’m using CPT pagination chaining as outlined here. And have the following on page-blog.php to show only posts on this page:

    /* Template Name: Blog */
    $paged = 1;
    if ( get_query_var('paged') ) $paged = get_query_var('paged');
    if ( get_query_var('page') ) $paged = get_query_var('page');
    query_posts( '&post_type=post&paged=' . $paged );
    require_once( 'archive-blog.php' );

    Does anyone know a way I can have tags displaying all post types while keeping the blog posts working correctly?


    [No bumping, thank you.]

  • The topic ‘Custom Post Type on home.’ is closed to new replies.