Hotfix/#8 Replace custom search endpoint with WP 5.0 search endpoint#9
Hotfix/#8 Replace custom search endpoint with WP 5.0 search endpoint#9coreymcollins wants to merge 2 commits intomasterfrom
Conversation
davebonds
left a comment
There was a problem hiding this comment.
@coreymcollins Left a couple of comments for you to review.
| */ | ||
| public function rest_api_init() { | ||
| register_rest_route('wds-react-post-search/v1', '/search', [ | ||
| register_rest_route( 'wp/v2', '/search', [ |
There was a problem hiding this comment.
Since this is a core route now as of 5.0, I think by registering a route here, we may be conflicting with the core route. If we're going to use the core route, we will be breaking things on SIG Perks, since our filters for modifying the tax query and orderby parameters would no longer work. While I like the idea of using a core route, I think we should wait to use that until we know what we'll need to change on SIG to make it work.
| endif; | ||
|
|
||
| if ( empty( $results ) ) : | ||
| return new WP_Error( 'wds-react-post-search-results', apply_filters( 'wds_react_post_search_no_results_text', esc_html__( 'No results found.', 'wds-react-post-search' ) ) ); |
There was a problem hiding this comment.
I think if we just return a string with rest_ensure_response( apply_filters( 'wds_react_post_search_no_results_text', esc_html__( 'No results found.', 'wds-react-post-search' ) ) );, instead of a WP_Error object, that should fix the 500 error.
Closes #8
It looks like the issue might be coming from this commit: 605d490
With this chunk of code specifically: 605d490#diff-79e5a3319d8cd2b1598acd07d412f4a0R419
Basically, we're asking for an error message to be returned if there are no results found. If we remove this, the plugin still works as expected with returning the "No results found." text below the search input while also no longer showing a 500 error.
In addition, I've also updated our route to use
/wp/v2/rather than our/wds-react-post-search/v1/and everything continues to work smoothly.If y'all could give this a test on your locals and let me know if you run into anything, that'd be great!
With my testing: