`get_posts()` ignore my custom post
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
get-posts
add a comment |
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
get-posts
add a comment |
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
get-posts
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
get-posts
get-posts
asked Jan 19 at 11:08
Sébastien SerreSébastien Serre
265
265
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If we do not specify POst_type, WordPress is search only on 'posts'
array( 'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );```
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "110"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f326074%2fget-posts-ignore-my-custom-post%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If we do not specify POst_type, WordPress is search only on 'posts'
array( 'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );```
add a comment |
If we do not specify POst_type, WordPress is search only on 'posts'
array( 'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );```
add a comment |
If we do not specify POst_type, WordPress is search only on 'posts'
array( 'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );```
If we do not specify POst_type, WordPress is search only on 'posts'
array( 'post_type' => array( 'cantine', 'post' ),
'post__in' => $ids,
'posts_per_page' => 5,
) );```
answered Jan 19 at 11:31
Sébastien SerreSébastien Serre
265
265
add a comment |
add a comment |
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f326074%2fget-posts-ignore-my-custom-post%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown