admin管理员组

文章数量:1277397

I'm using below wp-cli command to get latest post ID:

wp post list --order='DESC' --orderby='ID' --field='ID' | head -1

This, however is inefficient as all posts are retrieved from DB and then head limits the number of returned posts.

Is there a way to limit the number of returned posts using wp query?

I'm using below wp-cli command to get latest post ID:

wp post list --order='DESC' --orderby='ID' --field='ID' | head -1

This, however is inefficient as all posts are retrieved from DB and then head limits the number of returned posts.

Is there a way to limit the number of returned posts using wp query?

Share Improve this question asked Oct 30, 2021 at 11:06 rokpotorokpoto 2243 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Simply add:

--posts_per_page=1

to limit the queried items to a single item.

本文标签: wp cliGet last published post in Wordpress using wpcli