Home > Back-end >  Getting total number of post in current page
Getting total number of post in current page

Time:04-10

I've trying to display the number of posts in current page while using pagination. For the total posts among all pages I've used $query->found_posts;. However, I have no clue about counting post on each page. For example, I want to display Showing 5 of 50 posts Any idea? Thanks in advance.

CodePudding user response:

Similarly to found_posts, there's also post_count, which represents "the number of posts for the current query". So you can use $query->post_count.

Ref: https://github.com/WordPress/wordpress-develop/blob/0ea7a38664746f9ad4f402768975c66928817531/src/wp-includes/class-wp-query.php#L100

  • Related