title: Optimizing a query to show recent posts with a "View All" link when postcount exceeds maxpost setting
body: <p>I have a setting in my theme that allows the site owner to set the maximum number of posts (<code>$maxPosts</code>) to display in a "Recent Posts" menu. I'm using a custom script to generate the recent posts (because the <code>Recent Posts</code> widget does not highlight the current page, which I need for my css).</p>
  
  <p>My menu also is set up to display a "View All" link below the post listing, but only if the actual post count is <code>&gt; $maxposts</code>.</p>
  
  <p>I'm trying to work out the best method for getting the post count and comparing it to <code>$maxposts</code> in order to determine whether or not to show a "View All" link.</p>
  
  <p>I'm sure there's probably a better way, but here's my code. I'm looking to optimize it to support very large post counts:</p>
  
  <pre><code>$cat=get_cat_ID('excludeFromRecentPosts'); 
  $catHidden=get_cat_ID('hidden');
  $myquery = new WP_Query();
  $myquery-&gt;query(array(
      'cat' =&gt; "-$cat,-$catHidden",
      'post_not_in' =&gt; get_option('sticky_posts')
  ));
  $myrecentpostscount = $myquery-&gt;found_posts;
  if ($myrecentpostscount &gt; 0) 
  {
  //show the menu
  
  if ($myrecentpostscount &gt; $maxPosts)
  {
  //show "View All" link
  }
  }
  </code></pre>
  
  <p>I really only need to determine if the total post count from the query is greater than the <code>maxPost</code> setting in order to determine whether to show the "View All" link, so I'm trying to optimize the script to account for the case when there might be thousands of posts matching the criteria.</p>
  
  <p>And in that case, to avoid performance issues, I don't need to get a count of all of them. I just need to count up until the point of <code>maxPosts + 1</code>, and that's where I'm struggling a bit because the user could elect to make <code>maxPosts = -1</code> which means they want to show all posts. But this would be impractical, so I would probably set a upper limit of 20 when <code>maxPosts = -1</code>.</p>