• Resolved FlaviaS

    (@flavias)


    Hello

    My category.php display the regular post type (‘post’), but not my custom post type (‘video’).
    This is my code:

    <section id="list"class="main-column">
    			<div class="clearfix posts-container-fullsize"> 
    
    				<h2> <span class="title single-page title-list-page fa fa-square">
    				 <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; }?></span></h2>
    
    				<?php
    					if (have_posts()) : while ( have_posts() ) : the_post();
    				?>

    If I add the line query_posts( array( 'post_type' => array('post','video') ) ); right before if (have_posts()) : while ( have_posts() ) : the_post(); it shows all the post types from all categories.

    If I use a simple loop, it only shows the posts from one category, but only post with the regular post type.

    How can I display multiple post types with the same category in my category.php?

    thanks

Viewing 1 replies (of 1 total)
  • Thread Starter FlaviaS

    (@flavias)

    This was my solution ( on functions.php):

    add_filter( 'pre_get_posts', 'my_get_posts' );
    
    		function my_get_posts( $query ) {
    
    			if ( ( is_category () && $query->is_main_query() ) || is_feed() )
    			$query->set( 'post_type', array( 'post', 'video' ) );
    
    		return $query;
    		}
Viewing 1 replies (of 1 total)

The topic ‘Category.php not showing custom post type’ is closed to new replies.