equal
deleted
inserted
replaced
34 ) |
34 ) |
35 ); |
35 ); |
36 } |
36 } |
37 |
37 |
38 /** |
38 /** |
39 * Searches the object type content for a given search request. |
39 * Searches terms for a given search request. |
40 * |
40 * |
41 * @since 5.6.0 |
41 * @since 5.6.0 |
42 * |
42 * |
43 * @param WP_REST_Request $request Full REST request. |
43 * @param WP_REST_Request $request Full REST request. |
44 * @return array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing |
44 * @return array { |
45 * an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the |
45 * Associative array containing found IDs and total count for the matching search results. |
46 * total count for the matching search results. |
46 * |
|
47 * @type int[] $ids Found term IDs. |
|
48 * @type string|int|WP_Error $total Numeric string containing the number of terms in that |
|
49 * taxonomy, 0 if there are no results, or WP_Error if |
|
50 * the requested taxonomy does not exist. |
|
51 * } |
47 */ |
52 */ |
48 public function search_items( WP_REST_Request $request ) { |
53 public function search_items( WP_REST_Request $request ) { |
49 $taxonomies = $request[ WP_REST_Search_Controller::PROP_SUBTYPE ]; |
54 $taxonomies = $request[ WP_REST_Search_Controller::PROP_SUBTYPE ]; |
50 if ( in_array( WP_REST_Search_Controller::TYPE_ANY, $taxonomies, true ) ) { |
55 if ( in_array( WP_REST_Search_Controller::TYPE_ANY, $taxonomies, true ) ) { |
51 $taxonomies = $this->subtypes; |
56 $taxonomies = $this->subtypes; |
63 |
68 |
64 if ( ! empty( $request['search'] ) ) { |
69 if ( ! empty( $request['search'] ) ) { |
65 $query_args['search'] = $request['search']; |
70 $query_args['search'] = $request['search']; |
66 } |
71 } |
67 |
72 |
|
73 if ( ! empty( $request['exclude'] ) ) { |
|
74 $query_args['exclude'] = $request['exclude']; |
|
75 } |
|
76 |
|
77 if ( ! empty( $request['include'] ) ) { |
|
78 $query_args['include'] = $request['include']; |
|
79 } |
|
80 |
68 /** |
81 /** |
69 * Filters the query arguments for a REST API search request. |
82 * Filters the query arguments for a REST API term search request. |
70 * |
83 * |
71 * Enables adding extra arguments or setting defaults for a term search request. |
84 * Enables adding extra arguments or setting defaults for a term search request. |
72 * |
85 * |
73 * @since 5.6.0 |
86 * @since 5.6.0 |
74 * |
87 * |
95 self::RESULT_TOTAL => $total, |
108 self::RESULT_TOTAL => $total, |
96 ); |
109 ); |
97 } |
110 } |
98 |
111 |
99 /** |
112 /** |
100 * Prepares the search result for a given ID. |
113 * Prepares the search result for a given term ID. |
101 * |
114 * |
102 * @since 5.6.0 |
115 * @since 5.6.0 |
103 * |
116 * |
104 * @param int $id Item ID. |
117 * @param int $id Term ID. |
105 * @param array $fields Fields to include for the item. |
118 * @param array $fields Fields to include for the term. |
106 * @return array Associative array containing all fields for the item. |
119 * @return array { |
|
120 * Associative array containing fields for the term based on the `$fields` parameter. |
|
121 * |
|
122 * @type int $id Optional. Term ID. |
|
123 * @type string $title Optional. Term name. |
|
124 * @type string $url Optional. Term permalink URL. |
|
125 * @type string $type Optional. Term taxonomy name. |
|
126 * } |
107 */ |
127 */ |
108 public function prepare_item( $id, array $fields ) { |
128 public function prepare_item( $id, array $fields ) { |
109 $term = get_term( $id ); |
129 $term = get_term( $id ); |
110 |
130 |
111 $data = array(); |
131 $data = array(); |
130 * Prepares links for the search result of a given ID. |
150 * Prepares links for the search result of a given ID. |
131 * |
151 * |
132 * @since 5.6.0 |
152 * @since 5.6.0 |
133 * |
153 * |
134 * @param int $id Item ID. |
154 * @param int $id Item ID. |
135 * @return array Links for the given item. |
155 * @return array[] Array of link arrays for the given item. |
136 */ |
156 */ |
137 public function prepare_item_links( $id ) { |
157 public function prepare_item_links( $id ) { |
138 $term = get_term( $id ); |
158 $term = get_term( $id ); |
139 |
159 |
140 $links = array(); |
160 $links = array(); |