Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When you go to something like: site.com/?cat=2&page=2

you might see 3 posts, the page before might have 5 posts. I am looking for a way to count the posts on a given page. so if I am on page 2, with three posts, said function should return 3.

any idea?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

The query object contains the member var post_count which will give you the number of posts on the current page:

$wp_query->post_count;

Also, for the total number of posts for the query (across all pages):

$wp_query->found_posts;

and the number of pages in the query:

$wp_query->max_num_pages;
share|improve this answer
    
Post count gives me 26 back when I only have 13 posts in total and 10 on a given page...... This is for a category. there is a maximum of 2 pages. It returns 7 pages for max_num_posts. There are 13 posts for this category....wheres 26 coming from? and the 7? –  TheWebs Jul 25 '13 at 15:35
add comment

why not do a count?

 <?php count( $wp_query->posts ); ?>
share|improve this answer
    
"This answer was automatically flagged as low-quality because of its length and content", which I am sure you don't want. Please explain why this could solve the problem. –  s_ha_dum Jul 24 '13 at 22:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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