wp cli - WordPress API - count posts

Is there a way to count the number of postspages via the WordPress API?I'm wanting to insert a post then check,

Is there a way to count the number of posts / pages via the WordPress API?

I'm wanting to insert a post then check, using the API, that the count has gone up by 1.

I've looked at .getPosts

Is there a way to count the number of posts / pages via the WordPress API?

I'm wanting to insert a post then check, using the API, that the count has gone up by 1.

I've looked at http://codex.wordpress/XML-RPC_WordPress_API/Posts#wp.getPosts

Share Improve this question asked Sep 22, 2015 at 19:50 SnowcrashSnowcrash 3273 silver badges14 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

Assuming you are using Linux or OS X, the easiest way is probably to use wp-cli (if present in your WordPress installation) to return a list of all posts:

wp-cli post list

Then pipe it to the word count tool to get the number of lines:

wc -l

Finally, deduct one to take care of the header line which is not a post:

awk '{print $1-1}'

So, in one line:

wp-cli post list | wc -l | awk '{print $1-1}'

With WP-CLI installed from https://wp-cli/ you can retrieve the total post count by using:

wp post list --format=count

Full documentation for the POST LIST command

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745598779a4635277.html

相关推荐

  • wp cli - WordPress API - count posts

    Is there a way to count the number of postspages via the WordPress API?I'm wanting to insert a post then check,

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信