admin管理员组文章数量:1193314
I don't understand why the code below is always displaying the same number of returned post = 5. When I change the $variable
value to another post id
of a post with an author with another author_id
, I always get 5 returned posts, even if the authors have tens of posts. What am I doing wrong?
$variable=328;
$post = get_post($variable);
$author = get_userdata($post->post_author);
$args = array(
'author' => $author->id );
global $post;
$myposts = get_posts( $args );
$count= count($myposts);
echo '<pre dir="ltr">';
print_r($myposts);
echo '</pre>';
echo $count;
Your help is really apprecieted.
I don't understand why the code below is always displaying the same number of returned post = 5. When I change the $variable
value to another post id
of a post with an author with another author_id
, I always get 5 returned posts, even if the authors have tens of posts. What am I doing wrong?
$variable=328;
$post = get_post($variable);
$author = get_userdata($post->post_author);
$args = array(
'author' => $author->id );
global $post;
$myposts = get_posts( $args );
$count= count($myposts);
echo '<pre dir="ltr">';
print_r($myposts);
echo '</pre>';
echo $count;
Your help is really apprecieted.
Share Improve this question edited Jul 8, 2013 at 16:17 whiteletters in blankpapers asked Jul 8, 2013 at 13:46 whiteletters in blankpaperswhiteletters in blankpapers 3811 gold badge10 silver badges31 bronze badges 2- Have you tried examining the queries using the WP Debug Bar and Debug Bar Extender? This might shed some light on what's happening. Likely it's using the default # of posts which is defined in the backend under Settings > Reading. – Bendoh Commented Jul 8, 2013 at 13:48
- Thank you for your quick feedback. I have the # of posts in backend set to 100. I dont have WP Debug Bar and Debug Bar Extender. those are WP plugins? – whiteletters in blankpapers Commented Jul 8, 2013 at 13:49
2 Answers
Reset to default 2get_posts()
has some defaults set, including numberposts
equal to 5
. Since it's not considered to be a loop by itself those are independent and not affected by admin settings.
So simply pass in arguments numberposts
/posts_per_page
(same thing) number for how many posts you want or -1
for all matching posts.
Do this and get 50 posts. Give any number what you want to return
$args = array( 'numberposts' => 50,
'author' => $author->id );
本文标签: wp querygetposts always returning the same number of posts5
版权声明:本文标题:wp query - get_posts always returning the same number of posts = 5 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738485638a2089399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论