0
votes

I've got a problem with a query. I've got 4 different post_type. I would like to retrieve the posts from all post type from one category named 'une'. But it shows only post type from two post type => spectacles and post.

Here is my code :

<?php 
query_posts(array(
'post_type' => array('post','videos','photos','spectacles'),
'showposts' => -1,
'category_name' => 'une',
)
); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>

<?php endwhile; else: ?>
<?php endif; ?>

It is like category_name doesn't work for my query.

1
Please check again that the category taxonomy as well as category une is associated with all the post types and posts. I think the category taxonomy is not associated with all the post types. - CodeMascot
The post type are all registered like this register_post_type( 'photos', array( 'labels' => array( 'name' => __( 'Photos' ), 'singular_name' => __( 'Photo' ) ), 'public' => true, 'taxonomies' => array('category','post_tag'), 'has_archive' => true, 'supports' => array('title','content','editor','excerpt','thumbnail'), ) ); - Ben Belek
Can you see the default post category taxonomy at photos post type at backend dashboard ? - CodeMascot
Yes ! For all the post type ! - Ben Belek
@the_dramatist i found the solution !!! Thank you very much !!! - Ben Belek

1 Answers

0
votes

I found the solution to my problem, i add this to the functions.php

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'nav_menu_item', 'spectacles','historique','photos','videos'
        ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );