0

I am using the BracketPress plugin and trying to pull all of the posts of post_type brackets so I can send a newsletter blast to everyone with their current leaderboard position. However the get_posts that I am using seems to only pull half of the posts I should be pulling. Here's the code I am using.

$leaderboard_args = array(
    'meta_key'      =>  'score',
    'orderby'       =>  'meta_value',
    'order'         =>  'DESC',
    'post_type'     =>  'brackets'
);

$leaderboard = get_posts($leaderboard_args);
echo "<!--";
print_r($leaderboard);
echo '-->';

If you go to this link and view source you can see the array being outputted. The problem is, in the database there are 10 posts with post_type of brackets that have the meta_key score so I can't see any reason why they wouldn't be pulled. Even the master bracket (which should have the highest score and thus be pulled first) isn't getting pulled.

I am going to make some edits with more information as I dig through the database and try to figure this out.

  • 1
    Most probably your posts per page setting for your site is less than 10 – Pieter Goosen Feb 26 '15 at 16:56
  • @PieterGoosen Yeah... adding nopaging and posts_per_page to the agrs fixed the issue. If you want to make that an answer I will accept it. Next time instead of immediately jumping into the database and freaking out I should look for the simple solution. – CaldwellYSR Feb 26 '15 at 16:58
  • "sticky" post can contribute to this effect. I don't know if that is the case with your problem. wordpress.stackexchange.com/a/85658/21376 – s_ha_dum Feb 26 '15 at 17:20
1

As stated in comments

Most probably your posts per page setting for your site is less than 10

One have to remember, get_posts uses WP_Query. Any new instance of WP_Query and the main query (which also uses WP_Query) uses the value set for Blog pages show at most as default for the posts_per_page parameter when this parameter is not explicitly set by the user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.