WidgetCoreWidgetCore Documentation

The search REST endpoint

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)

These are the default query guarantees. Custom wgcr_search_query_args filters run after the base arguments are built and can change them: preserve post_status => publish, has_password => false, public searchable post types and sensible limits. The public route does not reapply those constraints after filters.

Parameters

ParameterTypeDefaultDescription
qstring—Required; the search query, at least 2 characters
typestringpostOne public, searchable post type; attachment and elementor_library are excluded; invalid values fall back to post
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. rand is reshuffled on every request, so with page a result can repeat on another page or be skipped
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. With 0, sticky posts are moved to the top of the current page of results only, not across pages
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
titlestringTitle with tags removed and HTML entities decoded
linkstringPermalink
thumbstringThumbnail URL, an empty string when there is none
excerptstringTags and shortcodes removed, trimmed to 18 words with an ellipsis when truncated; HTML entities decoded
datestringPublish date in the site’s configured date format (get_the_date)
htmlstringOptional: visible output from a published elementor_library template, with Elementor available

The six base fields are always returned. thumb and excerpt display controls affect the browser rendering, not the REST payload; there are no REST parameters to omit these fields. The sample date is illustrative, not a fixed wire format. There is no built-in “All post types” source.

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)
400Missing q: rest_missing_callback_param; invalid type or fewer 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