If numberposts = -1 offset won't work

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
1
down vote

favorite












I have an issue with a shortcode I have built. The short code pulls the most recent posts based off of certain parameters. below are the parameters



extract( shortcode_atts( array (
'numberposts' => 6,
'offset' => 0,
'featured' => null,
'trending' => null,
'showdate' => null
), $atts ) );

$args = array(
'numberposts' => $numberposts,
'offset' => $offset,
'category__not_in' => array(391),
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);


I am running this shortcode three times on the home page. The first time is like this:
(This one grabs the most recent 6 articles)



[recent-articles-grid featured="1" trending="1" showdate="1"]


The second time like this:
(This one grabs the next 4 articles)



[recent-articles-grid numberposts="4" offset="6" showdate="1"]


and the third time like this:
(This one is supposed to grab the remaining articles minus the first 10)



[recent-articles-grid numberposts="-1" offset="10"]


I have discovered that when I use -1 for the numberposts parameter it disregards the offset parameter. if I were to change the numberposts to something like 100 the offset works.



Is there a way to grab the remaining posts and still use the offset?










share|improve this question





























    up vote
    1
    down vote

    favorite












    I have an issue with a shortcode I have built. The short code pulls the most recent posts based off of certain parameters. below are the parameters



    extract( shortcode_atts( array (
    'numberposts' => 6,
    'offset' => 0,
    'featured' => null,
    'trending' => null,
    'showdate' => null
    ), $atts ) );

    $args = array(
    'numberposts' => $numberposts,
    'offset' => $offset,
    'category__not_in' => array(391),
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'post',
    'post_status' => 'publish'
    );


    I am running this shortcode three times on the home page. The first time is like this:
    (This one grabs the most recent 6 articles)



    [recent-articles-grid featured="1" trending="1" showdate="1"]


    The second time like this:
    (This one grabs the next 4 articles)



    [recent-articles-grid numberposts="4" offset="6" showdate="1"]


    and the third time like this:
    (This one is supposed to grab the remaining articles minus the first 10)



    [recent-articles-grid numberposts="-1" offset="10"]


    I have discovered that when I use -1 for the numberposts parameter it disregards the offset parameter. if I were to change the numberposts to something like 100 the offset works.



    Is there a way to grab the remaining posts and still use the offset?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have an issue with a shortcode I have built. The short code pulls the most recent posts based off of certain parameters. below are the parameters



      extract( shortcode_atts( array (
      'numberposts' => 6,
      'offset' => 0,
      'featured' => null,
      'trending' => null,
      'showdate' => null
      ), $atts ) );

      $args = array(
      'numberposts' => $numberposts,
      'offset' => $offset,
      'category__not_in' => array(391),
      'orderby' => 'post_date',
      'order' => 'DESC',
      'post_type' => 'post',
      'post_status' => 'publish'
      );


      I am running this shortcode three times on the home page. The first time is like this:
      (This one grabs the most recent 6 articles)



      [recent-articles-grid featured="1" trending="1" showdate="1"]


      The second time like this:
      (This one grabs the next 4 articles)



      [recent-articles-grid numberposts="4" offset="6" showdate="1"]


      and the third time like this:
      (This one is supposed to grab the remaining articles minus the first 10)



      [recent-articles-grid numberposts="-1" offset="10"]


      I have discovered that when I use -1 for the numberposts parameter it disregards the offset parameter. if I were to change the numberposts to something like 100 the offset works.



      Is there a way to grab the remaining posts and still use the offset?










      share|improve this question















      I have an issue with a shortcode I have built. The short code pulls the most recent posts based off of certain parameters. below are the parameters



      extract( shortcode_atts( array (
      'numberposts' => 6,
      'offset' => 0,
      'featured' => null,
      'trending' => null,
      'showdate' => null
      ), $atts ) );

      $args = array(
      'numberposts' => $numberposts,
      'offset' => $offset,
      'category__not_in' => array(391),
      'orderby' => 'post_date',
      'order' => 'DESC',
      'post_type' => 'post',
      'post_status' => 'publish'
      );


      I am running this shortcode three times on the home page. The first time is like this:
      (This one grabs the most recent 6 articles)



      [recent-articles-grid featured="1" trending="1" showdate="1"]


      The second time like this:
      (This one grabs the next 4 articles)



      [recent-articles-grid numberposts="4" offset="6" showdate="1"]


      and the third time like this:
      (This one is supposed to grab the remaining articles minus the first 10)



      [recent-articles-grid numberposts="-1" offset="10"]


      I have discovered that when I use -1 for the numberposts parameter it disregards the offset parameter. if I were to change the numberposts to something like 100 the offset works.



      Is there a way to grab the remaining posts and still use the offset?







      shortcode recent-posts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago









      fuxia♦

      90.9k12171351




      90.9k12171351










      asked 3 hours ago









      Jason

      1196




      1196




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          This problem has pretty simple explanation ;) All you need to do is to take a look at Codex page for WP_Query and read about offset parameter:




          offset (int) - number of post to displace or pass over. Warning:
          Setting the offset parameter overrides/ignores the paged parameter and
          breaks pagination (Click here for a workaround). The 'offset'
          parameter is ignored when 'posts_per_page'=>-1 (show all posts) is
          used.




          So I'm afraid there is no easy workaround for that. Setting posts_per_page tells WP that you want to see all posts. So adding offset to that equation doesn't make much sense.



          On the other hand, if you already have all posts queried, then you can easily do the offset part by yourself - just ignore N first posts (not ideal, but it will work).



          And - based on numberposts you use these get_posts function? If so, then it's even easier to ignore first N posts - just start your loop from N-th.






          share|improve this answer




















          • Thank you. I am using arrays so I was able to slice the array by the offset amount.
            – Jason
            2 hours ago










          • @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
            – Krzysiek Dróżdż
            2 hours 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
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f315351%2fif-numberposts-1-offset-wont-work%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          This problem has pretty simple explanation ;) All you need to do is to take a look at Codex page for WP_Query and read about offset parameter:




          offset (int) - number of post to displace or pass over. Warning:
          Setting the offset parameter overrides/ignores the paged parameter and
          breaks pagination (Click here for a workaround). The 'offset'
          parameter is ignored when 'posts_per_page'=>-1 (show all posts) is
          used.




          So I'm afraid there is no easy workaround for that. Setting posts_per_page tells WP that you want to see all posts. So adding offset to that equation doesn't make much sense.



          On the other hand, if you already have all posts queried, then you can easily do the offset part by yourself - just ignore N first posts (not ideal, but it will work).



          And - based on numberposts you use these get_posts function? If so, then it's even easier to ignore first N posts - just start your loop from N-th.






          share|improve this answer




















          • Thank you. I am using arrays so I was able to slice the array by the offset amount.
            – Jason
            2 hours ago










          • @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
            – Krzysiek Dróżdż
            2 hours ago














          up vote
          3
          down vote



          accepted










          This problem has pretty simple explanation ;) All you need to do is to take a look at Codex page for WP_Query and read about offset parameter:




          offset (int) - number of post to displace or pass over. Warning:
          Setting the offset parameter overrides/ignores the paged parameter and
          breaks pagination (Click here for a workaround). The 'offset'
          parameter is ignored when 'posts_per_page'=>-1 (show all posts) is
          used.




          So I'm afraid there is no easy workaround for that. Setting posts_per_page tells WP that you want to see all posts. So adding offset to that equation doesn't make much sense.



          On the other hand, if you already have all posts queried, then you can easily do the offset part by yourself - just ignore N first posts (not ideal, but it will work).



          And - based on numberposts you use these get_posts function? If so, then it's even easier to ignore first N posts - just start your loop from N-th.






          share|improve this answer




















          • Thank you. I am using arrays so I was able to slice the array by the offset amount.
            – Jason
            2 hours ago










          • @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
            – Krzysiek Dróżdż
            2 hours ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          This problem has pretty simple explanation ;) All you need to do is to take a look at Codex page for WP_Query and read about offset parameter:




          offset (int) - number of post to displace or pass over. Warning:
          Setting the offset parameter overrides/ignores the paged parameter and
          breaks pagination (Click here for a workaround). The 'offset'
          parameter is ignored when 'posts_per_page'=>-1 (show all posts) is
          used.




          So I'm afraid there is no easy workaround for that. Setting posts_per_page tells WP that you want to see all posts. So adding offset to that equation doesn't make much sense.



          On the other hand, if you already have all posts queried, then you can easily do the offset part by yourself - just ignore N first posts (not ideal, but it will work).



          And - based on numberposts you use these get_posts function? If so, then it's even easier to ignore first N posts - just start your loop from N-th.






          share|improve this answer












          This problem has pretty simple explanation ;) All you need to do is to take a look at Codex page for WP_Query and read about offset parameter:




          offset (int) - number of post to displace or pass over. Warning:
          Setting the offset parameter overrides/ignores the paged parameter and
          breaks pagination (Click here for a workaround). The 'offset'
          parameter is ignored when 'posts_per_page'=>-1 (show all posts) is
          used.




          So I'm afraid there is no easy workaround for that. Setting posts_per_page tells WP that you want to see all posts. So adding offset to that equation doesn't make much sense.



          On the other hand, if you already have all posts queried, then you can easily do the offset part by yourself - just ignore N first posts (not ideal, but it will work).



          And - based on numberposts you use these get_posts function? If so, then it's even easier to ignore first N posts - just start your loop from N-th.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Krzysiek Dróżdż

          11.4k42636




          11.4k42636











          • Thank you. I am using arrays so I was able to slice the array by the offset amount.
            – Jason
            2 hours ago










          • @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
            – Krzysiek Dróżdż
            2 hours ago
















          • Thank you. I am using arrays so I was able to slice the array by the offset amount.
            – Jason
            2 hours ago










          • @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
            – Krzysiek Dróżdż
            2 hours ago















          Thank you. I am using arrays so I was able to slice the array by the offset amount.
          – Jason
          2 hours ago




          Thank you. I am using arrays so I was able to slice the array by the offset amount.
          – Jason
          2 hours ago












          @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
          – Krzysiek Dróżdż
          2 hours ago




          @Jason No problem. Slicing array is a nicest workaround you can get in here, I guess. At least without writing own SQLs.
          – Krzysiek Dróżdż
          2 hours ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f315351%2fif-numberposts-1-offset-wont-work%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery