Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions class-wds-react-post-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function enqueue_scripts() {
wp_enqueue_style( 'wds-react-post-search-styles' );

wp_localize_script( 'wds-react-post-search', 'wds_react_post_search', array(
'rest_search_posts' => rest_url( 'wds-react-post-search/v1/search' ),
'rest_search_posts' => rest_url( 'wp/v2/search' ),
'loading_text' => apply_filters( 'wds_react_post_search_loading_text', esc_html__( 'Loading results...', 'wds-react-post-search' ) ),
'no_results_text' => apply_filters( 'wds_react_post_search_no_results_text', esc_html__( 'No results found.', 'wds-react-post-search' ) ),
'length_error' => apply_filters( 'wds_react_post_search_length_error_text', esc_html__( 'Please enter at least 3 characters.', 'wds-react-post-search' ) ),
Expand Down Expand Up @@ -329,7 +329,7 @@ public function post_types_to_search() {
* @return void
*/
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.

'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'search_posts' ),
'args' => $this->get_search_args(),
Expand Down Expand Up @@ -407,10 +407,6 @@ public function search_posts( $request ) {
endforeach;
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.

endif;

return rest_ensure_response( $results );
}
}
Expand Down