If numberposts = -1 offset won't work
Clash 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?
shortcode recent-posts
add a comment |Â
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?
shortcode recent-posts
add a comment |Â
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?
shortcode recent-posts
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
shortcode recent-posts
edited 3 hours ago
fuxiaâ¦
90.9k12171351
90.9k12171351
asked 3 hours ago
Jason
1196
1196
add a comment |Â
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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
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
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
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
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