WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type on home. (1 post)

  1. Darrenmooney
    Member
    Posted 10 months ago #

    Hey,

    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:

    <?php
    
    /* 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?

    Thanks,
    Darren.

    [No bumping, thank you.]

Reply

You must log in to post.

About this Topic

Tags