I have question about to create two custom post type the first one is already exist is "post" and the second "Product" I created it using this code :
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'product',
array(
'labels' => array(
'name' => __( 'Product' ),
'singular_name' => __( 'Product' )
),
'public' => true ,
'supports' => array( 'title', 'editor', 'thumbnail')
)
);
register_taxonomy( 'couleur', 'product', array( 'hierarchical' => true, 'label' => 'Couleur', 'query_var' => true, 'rewrite' => true ) );
}
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() )
$query->set( 'post_type', array( 'product' ) );
return $query;
}
The problem is when I fetch posts from database for them both,that means I display "post" and "product" in the same page "index.php" , the problem is that just one display in the page not them both :
product show => post(default) => hide
post(default) hide => product show
Add this in your
functions.php
fileAlso
$query->set('post_type', 'any');
is mentioned here but never tried. Check this too.