I have a Custom Post Type:
function thfo_register_cantine() {
$labels = array(
'name' => 'Cantines',
'singular_name' => 'Cantine',
'menu_name' => 'Cantine',
'all_items' => 'Tous les Menus',
'add_new' => 'Ajouter un menu',
'add_new_item' => 'Ajouter un menu',
'edit' => 'Modifier',
'edit_item' => 'Modifier le menu',
'new_item' => 'Nouveau menu',
'view' => 'Voir',
'view_item' => 'Voir le menu',
'search_items' => 'Chercher un menu',
'not_found' => 'Rien de trouver',
'not_found_in_trash' => 'Non trouvé dans la corbeille',
);
$args = array(
'labels' => $labels,
'description' => '',
'public' => true,
'show_ui' => true,
'has_archive' => true,
'show_in_menu' => true,
'exclude_from_search' => false,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'cantine', 'with_front' => true ),
'query_var' => true,
'supports' => array( 'title' ),
'show_in_rest' => true,
'publicly_queryable' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'show_in_admin_menu' => true,
'show_in_nav_menus' => true,
'can_export' => true,
);
register_post_type( 'cantine', $args );
}
On front-page.php
, If I ask
get_posts( array('post_type' => array( 'cantine' ),'posts_per_page' => 2,));
I have my 2 posts but if I ask
get_posts( array( 'post__in' => $ids, 'posts_per_page' => 5 ) );
Where $ids
is an array with my CPT ids, then, I haven't any results ...
Do you have any ideas why ?
Many thanks
I have a Custom Post Type:
function thfo_register_cantine() {
$labels = array(
'name' => 'Cantines',
'singular_name' => 'Cantine',
'menu_name' => 'Cantine',
'all_items' => 'Tous les Menus',
'add_new' => 'Ajouter un menu',
'add_new_item' => 'Ajouter un menu',
'edit' => 'Modifier',
'edit_item' => 'Modifier le menu',
'new_item' => 'Nouveau menu',
'view' => 'Voir',
'view_item' => 'Voir le menu',
'search_items' => 'Chercher un menu',
'not_found' => 'Rien de trouver',
'not_found_in_trash' => 'Non trouvé dans la corbeille',
);
$args = array(
'labels' => $labels,
'description' => '',
'public' => true,
'show_ui' => true,
'has_archive' => true,
'show_in_menu' => true,
'exclude_from_search' => false,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'cantine', 'with_front' => true ),
'query_var' => true,
'supports' => array( 'title' ),
'show_in_rest' => true,
'publicly_queryable' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'show_in_admin_menu' => true,
'show_in_nav_menus' => true,
'can_export' => true,
);
register_post_type( 'cantine', $args );
}
On front-page.php
, If I ask
get_posts( array('post_type' => array( 'cantine' ),'posts_per_page' => 2,));
I have my 2 posts but if I ask
get_posts( array( 'post__in' => $ids, 'posts_per_page' => 5 ) );
Where $ids
is an array with my CPT ids, then, I haven't any results ...
Do you have any ideas why ?
Many thanks
Share Improve this question asked Jan 19, 2019 at 11:08 Sébastien SerreSébastien Serre 4843 silver badges9 bronze badges1 Answer
Reset to default 2If we do not specify post types, WordPress searches only 'posts'
$actus_new = get_posts( array(
'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );