question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any way to get total posts count?

See original GitHub issue

Hello!

According to the official docs: https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/

“To determine how many pages of data are available, the API returns two header fields with every paginated response: X-WP-Total: the total number of records in the collection X-WP-TotalPages: the total number of pages encompassing all available records”

I query posts using await client.Posts.Query(query), with ‘Page’ and ‘PerPage’ parameters set, but this method only returns posts. Is there a way to get total posts count without actually loading all of them with client.Posts.GetAll()?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomasPecommented, May 13, 2021

Hey, thanks so much for your work. I’ll try to check it out on the weekend!

1reaction
marinasundstromcommented, May 12, 2021

My prototype: https://github.com/robertsundstrom/WordPressPCL/tree/queryresult

I created the QueryResult<T> class, and substituted the return type of Query (IEnumerable<T>) with it. It would not be a big deal since QueryResult<t> is implementing IEnumerable<T>.

The added properties of QueryResult<T> are Total and TotalPages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wp_count_posts() | Function - WordPress Developer Resources
The wp_count_posts() can be used to find the number for post statuses of any post type. This includes attachments or any post type...
Read more >
Get post count of current loop when using multiple queries ...
There is another way that I use within the loop that counts posts using current_post + 1 , for example. <?php $my_query =...
Read more >
WordPress get count of posts without using get_posts()?
$myCount = $wp_query->found_posts;. That will return the number of posts found for the last query. If you want to count the number of...
Read more >
How to Show Total Number of Posts in WordPress
Now you can use the shortcode [total_posts] to display total number of posts in any posts, pages, or sidebar widgets. We hope this...
Read more >
How to Display the Total Number of Posts on Your ...
On the left-hand admin panel, click on Settings and select the Simple Blog Stats option. click on Settings and select the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found