WidgetCoreWidgetCore Documentation

REST API

The WidgetCore search REST endpoint — the route, every parameter with its type and default, the response shape, pagination headers, request examples and the status codes.

The search widget and the shortcode both talk to a single REST endpoint. You can call it yourself from JavaScript, from a mobile app or from another plugin.

The endpoint

ItemValue
Namespacewgcr/v1
Route/search
Full addresshttps://example.com/wp-json/wgcr/v1/search
MethodGET
Permission callback__return_true (public)
Result capWGCR_SEARCH_MAX_RESULTS (50)

Parameters

ParameterTypeDefaultDescription
qstring—Required; the search query, at least 2 characters
typestringpostThe source post type
limitnumber5Number of results; clamped to 1–50
templatenumber0Elementor template id used to render results
pagenumber0Page number; when greater than 0 the count headers are returned
orderbystringrelevancerelevance, date, title, author, rand, menu_order
orderstringDESCASC or DESC
datestringallall, week, month, year
termsstringEmptyA comma separated list of [taxonomy:]id
terms_opstringexcludeinclude or exclude
ignore_stickynumber11 means sticky posts are not given priority
query_idstringEmptyThe key for the wgcr_search_query_args/{query_id} filter

q validation: if it is not a string, or shorter than 2 characters after trim, the response is a rest_invalid_param error.

The response shape

json
[
	{
		"id": 42,
		"title": "Getting started with the course",
		"link": "https://example.com/?p=42",
		"thumb": "https://example.com/wp-content/uploads/2026/09/cover-150x150.jpg",
		"excerpt": "A short text of about 18 words…",
		"date": "2026-09-01"
	}
]
FieldTypeNotes
idnumberPost id
titlestringEscaped title text
linkstringPermalink
thumbstring or nullThumbnail URL, null when there is none
excerptstringExcerpt with an ellipsis, empty when turned off
datestringPublish date in Y-m-d format
htmlstringOnly with template: the rendered Elementor template

Pagination headers

When page is greater than 0, two standard WordPress headers are added to the response:

X-WP-Total: 87
X-WP-TotalPages: 8
HeaderMeaning
X-WP-TotalTotal number of matching posts
X-WP-TotalPagesTotal number of pages at the requested limit

Examples

One request, four flavours — pick the tab that matches your stack.

curl -s "https://example.com/wp-json/wgcr/v1/search?q=course&limit=5&type=post"

# With pagination, reading the count headers
curl -sD - -o /dev/null "https://example.com/wp-json/wgcr/v1/search?q=course&limit=12&page=2" | grep -i "^x-wp"

When template is valid, every result carries an extra html field with that template rendered for that post. If the template is a draft or renders no visible content, html is not returned.

Server-side behaviour

StepWhat happens
1q is validated (at least 2 characters)
2type is sanitised; invalid values become post
3limit is clamped to 1…WGCR_SEARCH_MAX_RESULTS
4orderby, order, date, terms, terms_op are whitelisted
5The query args are built: post_status => publish, has_password => false
6The wgcr_search_query_args filter runs, then the {query_id} variant
7WP_Query runs and the results are mapped into the response fields
8With template, each post is rendered through Elementor
9With page > 0, the count headers are added

Status codes

StatusWhen
200A successful search (an empty array is still a success)
400q missing or shorter than 2 characters (rest_invalid_param)
404The REST API itself is unavailable or permalinks block it

An empty result is not an error: you get 200 with [], and the client shows the “No results found.” message.

Rate limiting and optimisation

The plugin adds no rate limiting of its own. On a busy site consider these measures:

MeasureEffect
Cache the route for anonymous users (short TTL)Fewer queries for popular terms
Keep limit at or below 12Smaller payloads
Turn thumbnails offFewer image requests
Add an index for your search-heavy post typeFaster WP_Query
Use query_id + a filter to narrow the query before it runsLess work in the database