WP rest API get post by title

BenB picture BenB · Oct 14, 2015 · Viewed 10k times · Source

I'm trying to check by a post title if post exist or not. For some reason when i try something like:

http://domain.com/wp-json/wp/v2/posts?filter[post-title]=table

I want if post with the name table exist, to get the post, if not, get an empty response. But for some reason when post with title not exist i get all posts back. How could get empty when no post exist and the post when it exist.

Answer

Black picture Black · Aug 6, 2017

Unfortunately it is not possible, but you can use slug instead. Slug is editable part of the URL when writing a post and they can represent title of the page (or it can be changed into this).

http://example.com/wp-json/wp/v2/posts?slug=table

More details: https://developer.wordpress.org/rest-api/reference/pages/#arguments