`get_posts()` ignore my custom post












1















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



























    1















    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

























      1












      1








      1








      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














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 11:08









      Sébastien SerreSébastien Serre

      265




      265






















          1 Answer
          1






          active

          oldest

          votes


















          2














          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,
          ) );```





          share|improve this answer























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            2














            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,
            ) );```





            share|improve this answer




























              2














              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,
              ) );```





              share|improve this answer


























                2












                2








                2







                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,
                ) );```





                share|improve this answer













                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,
                ) );```






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 11:31









                Sébastien SerreSébastien Serre

                265




                265






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                    Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                    A Topological Invariant for $pi_3(U(n))$