Exclude Posts from SEARCH WP REST API

Viewed 627

How can I exclude posts from the search endpoint in WP REST API?

I have:

'/wp-json/wp/v2/search?s=lorem&page=1&per_page=60&_embed&exclude=1392

where 1392 is the ID of excluding page, but it does not work...

https://developer.wordpress.org/rest-api/reference/search-results/

I can't pass exclude parameters to search results, but I have to exclude some posts from the WordPress search. Anyone know how can I do that? Thanks!

1 Answers

The exclude is an array, so to exclude the first post use exclude[0]=1392, to exclude a second post: exclude[1]=333

The test that worked for me uses this structure which is different to yours:

'/wp-json/wp/v2/posts?search=lorem&exclude[0]=1392'

Please note if you pass all the exclude ids through an array, the REST API will generate the exclude parameters positions for you.

Related