January 7, 2020 at 2:29 am
Hi, I’m trying to display Custom Posts into Post Grid/Carousel Block but they don’t show up.
The Block correctly shows the 2 Categories I’ve created for that post type but when I select the category I get the message “No posts found”.
I’ve created the Custom Post Type without plugins.
Here is the code:
function create_posttype() {
register_post_type('prodotti', array(
'labels' => array(
'name' => 'Prodotti',
'singular_name' => 'Prodotto',
'add_new' => 'Aggiungi Nuovo',
'edit_item' => 'Modifica Prodotto',
'all_items' => 'Tutti i Prodotti',
),
'public' => true,
'show_ui' => true,
'menu_icon' => 'dashicons-cart',
'capability_type' => 'post',
'has_archive' => true,
'publicly_queryable' => true,
'taxonomies' => array( 'category' ),
'supports' => array( 'title', 'excerpt', 'thumbnail', 'page-attributes', 'post-formats', 'revisions',),
)
);
}
add_action( 'init', 'create_posttype',0 );
I’ve also tried to add this code in the Functions.php file, but it doesn’t help.
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'prodotti');
$query->set('post_type',$post_type);
return $query;
}
}
Do I miss something?