Here are some basic examples of rest API for Relevanssi usage. Here you can find examples of GET request however you can submit POST requests also.
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=query
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=query&posts_per_page=5
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=query&posts_per_page=5&paged=2
Define post type and search multiple post types in a single query
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=query&posts_per_page=5&paged=2&type=post
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&type=post,page
Filter by taxonomy/taxonomies
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&tax_query[0][taxonomy]=category&tax_query[0][field]=id&tax_query[0][terms]=3
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&tax_query[tax_relation]=AND&tax_query[0][taxonomy]=category&tax_query[0][field]=id&tax_query[0][terms]=3&tax_query[1][taxonomy]=category&tax_query[1][field]=id&tax_query[1][terms]=2
Exclude categories via taxonomies request
https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&tax_query[0][taxonomy]=category&tax_query[0][field]=id&tax_query[0][terms]=3&tax_query[0][operator]=NOT IN
For multilingual websites (WPML & Polylang)
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=query&lang=en
Results order
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&type=post&orderby=modified&order=DESC
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&type=post&orderby=modified&order=ASC
- https://[your domain]/wp-json/relevanssi/v1/search?keyword=test&type=post&meta_key=some_key&orderby=meta_value|meta_value_num&order=ASC
Rest API for Relevanssi Demo wabsite
You can try plugin on our demo website http://demo.erlycoder.com/demo1/. For example you can try the following request:
Basic:
http://demo.erlycoder.com/demo1/wp-json/relevanssi/v1/search?keyword=test
Order posts by modification time:
http://demo.erlycoder.com/demo1/wp-json/relevanssi/v1/search?keyword=test&type=post&orderby=modified&order=DESC
http://demo.erlycoder.com/demo1/wp-json/relevanssi/v1/search?keyword=test&type=post&orderby=modified&order=ASC
Filter posts by taxonomy (one single category):
http://demo.erlycoder.com/demo1/wp-json/relevanssi/v1/search?keyword=test&tax_query[0][taxonomy]=category&tax_query[0][field]=id&tax_query[0][terms]=3
Filter posts by taxonomy (exclude category):
http://demo.erlycoder.com/demo1/wp-json/relevanssi/v1/search?keyword=test&tax_query[0][taxonomy]=category&tax_query[0][field]=id&tax_query[0][terms]=3&tax_query[0][operator]=NOT IN