2690

An easy way to get the total number of posts on a one-person WordPress site

An easy way to get the total number of posts on a one-person WordPress site

2012.11.17

You may often want to get the total number of articles, but if you think “I’m running it by myself If you can limit yourself to a “WordPress site”, I made a note of this because there was an easier way to do it.

Confirmation

Commonly seen codes

A lot of the code you see often looks like the following.

This in itself is perfectly fine, but it’s pretty long for just getting the total number of posts. I found a way to make it shorter, using the count_user_posts function.

How to get the total number of posts using the count_user_posts function

It is one line and short, as shown below.

The part 1 is the user ID. To find the user ID, mouse over the link in the name part of the target user name in the “User Management” screen. The user ID will be displayed in the URL display section at the bottom of the browser.
Then, the user ID will be displayed in the URL display part at the bottom of the browser and you can check the ID .

What this function does is that the specified user ID is published (publishes) and It is a function to display the number of articles in the site.