Is it possible to remove the posts_per_page limit on a specific post type?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I'd like to know if I can remove the limit on the posts_per_page for a specific post type.



In the archive.php page I'm displaying different post type, and for the specific "publications" post type I want to display all the posts. How can I achieve this without impacting the traditional "post" type?










share|improve this question







New contributor




VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    2
    down vote

    favorite












    I'd like to know if I can remove the limit on the posts_per_page for a specific post type.



    In the archive.php page I'm displaying different post type, and for the specific "publications" post type I want to display all the posts. How can I achieve this without impacting the traditional "post" type?










    share|improve this question







    New contributor




    VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'd like to know if I can remove the limit on the posts_per_page for a specific post type.



      In the archive.php page I'm displaying different post type, and for the specific "publications" post type I want to display all the posts. How can I achieve this without impacting the traditional "post" type?










      share|improve this question







      New contributor




      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'd like to know if I can remove the limit on the posts_per_page for a specific post type.



      In the archive.php page I'm displaying different post type, and for the specific "publications" post type I want to display all the posts. How can I achieve this without impacting the traditional "post" type?







      custom-post-types custom-post-type-archives






      share|improve this question







      New contributor




      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 hours ago









      VeeJay

      111




      111




      New contributor




      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      VeeJay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          You can hook into the pre_get_posts action, to access the $query object.



          You should use your action hook inside your functions.php.
          An example of what your function could look like:



          add_action( 'pre_get_posts', 'publications_archive_query' );
          function publications_archive_query( $query ) {
          if ( !is_admin() && $query->is_main_query())
          if ( $query->get('post_type') === 'publications' )
          $query->set( 'posts_per_page', 5 );




          Narrow down what is the query you are modifying by using conditional checks.



          $query->get('post_type') to get current's Query post_type to check against.



          is_main_query to make sure you are only applying your query modification to the main query.



          Read further and find more examples:
          https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts






          share|improve this answer


















          • 1




            I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
            – Krzysiek Dróżdż
            1 hour ago






          • 1




            @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
            – FFrewin
            44 mins ago







          • 1




            Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
            – Krzysiek Dróżdż
            17 mins ago










          • @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
            – FFrewin
            12 mins ago


















          up vote
          -1
          down vote













          If you are creating the query yourself inside those .php pages, then it's better to pass -1 in argument to obtain unlimited posts:



          $args = array( ...... 'posts_per_page'=>-1, .....) 
          $your_query = new WP_Query($args);


          If you dont have access to the query-creating .php file, then you might neeed to use less-recommended version (which affects all pages/queries with that custom-type), like @FFrewin suggested.






          share|improve this answer






















          • Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
            – Krzysiek Dróżdż
            13 mins ago










          • @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
            – T.Todua
            9 mins ago











          • Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
            – FFrewin
            7 mins ago











          • @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
            – T.Todua
            4 mins ago











          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          VeeJay is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f315582%2fis-it-possible-to-remove-the-posts-per-page-limit-on-a-specific-post-type%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          You can hook into the pre_get_posts action, to access the $query object.



          You should use your action hook inside your functions.php.
          An example of what your function could look like:



          add_action( 'pre_get_posts', 'publications_archive_query' );
          function publications_archive_query( $query ) {
          if ( !is_admin() && $query->is_main_query())
          if ( $query->get('post_type') === 'publications' )
          $query->set( 'posts_per_page', 5 );




          Narrow down what is the query you are modifying by using conditional checks.



          $query->get('post_type') to get current's Query post_type to check against.



          is_main_query to make sure you are only applying your query modification to the main query.



          Read further and find more examples:
          https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts






          share|improve this answer


















          • 1




            I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
            – Krzysiek Dróżdż
            1 hour ago






          • 1




            @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
            – FFrewin
            44 mins ago







          • 1




            Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
            – Krzysiek Dróżdż
            17 mins ago










          • @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
            – FFrewin
            12 mins ago















          up vote
          2
          down vote













          You can hook into the pre_get_posts action, to access the $query object.



          You should use your action hook inside your functions.php.
          An example of what your function could look like:



          add_action( 'pre_get_posts', 'publications_archive_query' );
          function publications_archive_query( $query ) {
          if ( !is_admin() && $query->is_main_query())
          if ( $query->get('post_type') === 'publications' )
          $query->set( 'posts_per_page', 5 );




          Narrow down what is the query you are modifying by using conditional checks.



          $query->get('post_type') to get current's Query post_type to check against.



          is_main_query to make sure you are only applying your query modification to the main query.



          Read further and find more examples:
          https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts






          share|improve this answer


















          • 1




            I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
            – Krzysiek Dróżdż
            1 hour ago






          • 1




            @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
            – FFrewin
            44 mins ago







          • 1




            Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
            – Krzysiek Dróżdż
            17 mins ago










          • @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
            – FFrewin
            12 mins ago













          up vote
          2
          down vote










          up vote
          2
          down vote









          You can hook into the pre_get_posts action, to access the $query object.



          You should use your action hook inside your functions.php.
          An example of what your function could look like:



          add_action( 'pre_get_posts', 'publications_archive_query' );
          function publications_archive_query( $query ) {
          if ( !is_admin() && $query->is_main_query())
          if ( $query->get('post_type') === 'publications' )
          $query->set( 'posts_per_page', 5 );




          Narrow down what is the query you are modifying by using conditional checks.



          $query->get('post_type') to get current's Query post_type to check against.



          is_main_query to make sure you are only applying your query modification to the main query.



          Read further and find more examples:
          https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts






          share|improve this answer














          You can hook into the pre_get_posts action, to access the $query object.



          You should use your action hook inside your functions.php.
          An example of what your function could look like:



          add_action( 'pre_get_posts', 'publications_archive_query' );
          function publications_archive_query( $query ) {
          if ( !is_admin() && $query->is_main_query())
          if ( $query->get('post_type') === 'publications' )
          $query->set( 'posts_per_page', 5 );




          Narrow down what is the query you are modifying by using conditional checks.



          $query->get('post_type') to get current's Query post_type to check against.



          is_main_query to make sure you are only applying your query modification to the main query.



          Read further and find more examples:
          https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 11 mins ago

























          answered 3 hours ago









          FFrewin

          1357




          1357







          • 1




            I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
            – Krzysiek Dróżdż
            1 hour ago






          • 1




            @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
            – FFrewin
            44 mins ago







          • 1




            Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
            – Krzysiek Dróżdż
            17 mins ago










          • @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
            – FFrewin
            12 mins ago













          • 1




            I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
            – Krzysiek Dróżdż
            1 hour ago






          • 1




            @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
            – FFrewin
            44 mins ago







          • 1




            Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
            – Krzysiek Dróżdż
            17 mins ago










          • @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
            – FFrewin
            12 mins ago








          1




          1




          I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
          – Krzysiek Dróżdż
          1 hour ago




          I’m afraid it won’t work. You use get_post_type to check post type. But this function checks post type of global $post variable. And during pre_get_post that variable is not set yet ;)
          – Krzysiek Dróżdż
          1 hour ago




          1




          1




          @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
          – FFrewin
          44 mins ago





          @KrzysiekDróżdż - yes you are right. Thanks for the note. I am editing the answer and also fixed a syntax error in my first if ().
          – FFrewin
          44 mins ago





          1




          1




          Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
          – Krzysiek Dróżdż
          17 mins ago




          Still not correct. 1. You still write about get_post_type. 2. post_type doesn't have to be set, so your can cause notices and warnings.
          – Krzysiek Dróżdż
          17 mins ago












          @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
          – FFrewin
          12 mins ago





          @KrzysiekDróżdż: yes - I only updated my code ... forgot to correct the rest of my answer. Thanks! Fixed now (hope I didn't miss anything else this time)
          – FFrewin
          12 mins ago













          up vote
          -1
          down vote













          If you are creating the query yourself inside those .php pages, then it's better to pass -1 in argument to obtain unlimited posts:



          $args = array( ...... 'posts_per_page'=>-1, .....) 
          $your_query = new WP_Query($args);


          If you dont have access to the query-creating .php file, then you might neeed to use less-recommended version (which affects all pages/queries with that custom-type), like @FFrewin suggested.






          share|improve this answer






















          • Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
            – Krzysiek Dróżdż
            13 mins ago










          • @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
            – T.Todua
            9 mins ago











          • Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
            – FFrewin
            7 mins ago











          • @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
            – T.Todua
            4 mins ago















          up vote
          -1
          down vote













          If you are creating the query yourself inside those .php pages, then it's better to pass -1 in argument to obtain unlimited posts:



          $args = array( ...... 'posts_per_page'=>-1, .....) 
          $your_query = new WP_Query($args);


          If you dont have access to the query-creating .php file, then you might neeed to use less-recommended version (which affects all pages/queries with that custom-type), like @FFrewin suggested.






          share|improve this answer






















          • Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
            – Krzysiek Dróżdż
            13 mins ago










          • @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
            – T.Todua
            9 mins ago











          • Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
            – FFrewin
            7 mins ago











          • @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
            – T.Todua
            4 mins ago













          up vote
          -1
          down vote










          up vote
          -1
          down vote









          If you are creating the query yourself inside those .php pages, then it's better to pass -1 in argument to obtain unlimited posts:



          $args = array( ...... 'posts_per_page'=>-1, .....) 
          $your_query = new WP_Query($args);


          If you dont have access to the query-creating .php file, then you might neeed to use less-recommended version (which affects all pages/queries with that custom-type), like @FFrewin suggested.






          share|improve this answer














          If you are creating the query yourself inside those .php pages, then it's better to pass -1 in argument to obtain unlimited posts:



          $args = array( ...... 'posts_per_page'=>-1, .....) 
          $your_query = new WP_Query($args);


          If you dont have access to the query-creating .php file, then you might neeed to use less-recommended version (which affects all pages/queries with that custom-type), like @FFrewin suggested.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 7 mins ago

























          answered 19 mins ago









          T.Todua

          2,15852146




          2,15852146











          • Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
            – Krzysiek Dróżdż
            13 mins ago










          • @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
            – T.Todua
            9 mins ago











          • Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
            – FFrewin
            7 mins ago











          • @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
            – T.Todua
            4 mins ago

















          • Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
            – Krzysiek Dróżdż
            13 mins ago










          • @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
            – T.Todua
            9 mins ago











          • Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
            – FFrewin
            7 mins ago











          • @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
            – T.Todua
            4 mins ago
















          Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
          – Krzysiek Dróżdż
          13 mins ago




          Well, modifying global wp_query using pre_get_posts is not less-recommended. You always should use global wp_query and modify it with filters, if it's only possible and not create your own queries.
          – Krzysiek Dróżdż
          13 mins ago












          @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
          – T.Todua
          9 mins ago





          @KrzysiekDróżdż I neither way agree with you and it's really "less-recommended" to modify the global query, and what's more no indication which pages you are affecting (and that affects any existing page with cpt publications). Instead, it's better to make a custom query (instead of altering whole site) within the targeted .php. However, you have right to downvote my question (with incorrect reason), and ok, it's your right.
          – T.Todua
          9 mins ago













          Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
          – FFrewin
          7 mins ago





          Creating a new WP_Query in this context leads to querying the database twice. As you have a second query over the main one.
          – FFrewin
          7 mins ago













          @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
          – T.Todua
          4 mins ago





          @FFrewin to say, actually i dont see any problem with that. You are not re-creating new queries on all pages, instead doing on sepcific pages, and even i dont think you have million of hits in hour on that page, to worry about DB overload (which is really good habbit to worry about overload and always try to have optimized code). But, in this case i dont see real problem. ok, i just suggested my answer, you decide.
          – T.Todua
          4 mins ago











          VeeJay is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          VeeJay is a new contributor. Be nice, and check out our Code of Conduct.












          VeeJay is a new contributor. Be nice, and check out our Code of Conduct.











          VeeJay is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f315582%2fis-it-possible-to-remove-the-posts-per-page-limit-on-a-specific-post-type%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery