Search WP API using the post title

I’m using the WP REST API v2 to try and search for all posts with the same title, what I’m trying to do is create a sort of head-to-head/previous meetings page for 2 teams.

At the moment i can retrieve a single post with a slug no problem

.../wp-json/sportspress/v2/events?slug=team1-vs-team2

When i use a search it retrieves all the events with team1 and team2, but also all references to team1 & 2 from post content which is not what I want…

.../wp-json/sportspress/v2/events?search=team1+team2

How do i retrieve a post using the search using the exact post title as shown below in title > rendered ??

0   
  id    60455
  date  "2016-11-22T19:30:00"
  date_gmt  "2016-11-22T19:30:00"
  modified  "2016-11-23T09:25:29"
  modified_gmt  "2016-11-23T07:25:29"
  slug  "team1-vs-team2"
  status    "publish"
  type  "sp_event"
  link  ".../event/team1-vs-team2/"
  title 
      rendered  "Team1 vs Team2"

2 s
2

Unfortunately, it is not possible, but you can use slug instead.

Like this:

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

Reference document URL are: https://developer.wordpress.org/rest-api/reference/pages/#arguments

Leave a Comment