Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP rest API get post by title

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.

like image 758
BenB Avatar asked Oct 14 '15 16:10

BenB


People also ask

How do I fetch API in WordPress?

If you want to use the Fetch API with WordPress, you simply have to call the fetch function in your JavaScript code. Follow that function with a . then handler to access the content. You can then display it on your website or in your web application.

What is WP JSON WP v2 posts?

To use the WordPress REST API, simply add /wp-json/wp/v2/posts to the end of your WordPress site URL. This will give you a list of posts (in JSON format). The default number of posts returned is 10, but you can choose to show more or less with the per_page argument — we'll talk about that below.


2 Answers

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

like image 179
Black Avatar answered Sep 24 '22 05:09

Black


According to http://v2.wp-api.org/, some have to use search keyword :
http://domain.com/wp-json/wp/v2/posts?search=table.

like image 44
Vasiu Alexandru Avatar answered Sep 20 '22 05:09

Vasiu Alexandru