Skip to content

Conversation

@coreymcollins
Copy link
Contributor

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:

  • I no longer receive 500 errors when there are no search results found
  • I still receive the expected "No results found." message when no search results are found
  • I still receive the expected results when searching for a term

@coreymcollins coreymcollins added the bug Something isn't working label Dec 9, 2018
@coreymcollins coreymcollins added the ready for review The issue or pull request is ready for testing and code review label Dec 9, 2018
Copy link
Contributor

@davebonds davebonds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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', [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' ) ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready for review The issue or pull request is ready for testing and code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants