Is there a way that I can add "Showing posts x to x of y" into a paginated custom post type loop? So for example if I have 100 posts I'm showing 10 posts per page, on /page/3 it would show "Showing posts 21 - 30 of 100".

1 Answer 1


All query objects have a few built in vars that can help you display this.

Assuming your custom query object is $query:

  • The total number of posts across all pages is $query->found_posts
  • The total number of posts for the current page is $query->post_count
  • The current page number is $query->query_vars['paged']
  • The number of posts per page is $query->query_vars['posts_per_page']

With that in mind, we can do something like this:

$pagenum = $query->query_vars['paged'] < 1 ? 1 : $query->query_vars['paged'];
$first = ( ( $pagenum - 1 ) * $query->query_vars['posts_per_page'] ) + 1;
$last = $first + $query->post_count - 1;
echo "Showing posts $first - $last of $query->found_posts";

EDIT - If you want to use the above with the main query, change all instances of $query to $wp_query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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