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?

1 Answer 1


Simply add:


to limit the queried items to a single item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.