| @@ -12,9 +12,9 @@ | ||
| 12 | 12 | * AJAX listener for autocomplete |
| 13 | 13 | */ |
| 14 | 14 | public function ajax() { |
| 15 | 15 | $q = ( isset( $_GET['q'] ) ) ? sanitize_text_field( $_GET['q'] ) : ''; |
| 16 | - $type = ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'page', 'post', 'category', 'post_type' ) ) ) ? $_GET['type'] : 'post'; | |
| 16 | + $type = ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'page', 'post', 'category', 'post_type', 'post_tag' ) ) ) ? $_GET['type'] : 'post'; | |
| 17 | 17 | |
| 18 | 18 | // do nothing if supplied 'q' parameter is omitted or empty |
| 19 | 19 | // or less than 2 characters long |
| 20 | 20 | if( empty( $q ) || strlen( $q ) < 2 ) { |
| @@ -35,8 +35,12 @@ | ||
| 35 | 35 | |
| 36 | 36 | case 'post_type': |
| 37 | 37 | echo $this->list_post_types( $q ); |
| 38 | 38 | break; |
| 39 | + | |
| 40 | + case 'post_tag': | |
| 41 | + echo $this->list_tags( $q ); | |
| 42 | + break; | |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | die(); |
| 42 | 46 | } |
| @@ -59,11 +63,22 @@ | ||
| 59 | 63 | * |
| 60 | 64 | * @return string |
| 61 | 65 | */ |
| 62 | 66 | protected function list_categories( $query ) { |
| 63 | - $categories = get_terms( 'category', array( 'name__like' => $query, 'fields' => 'names', 'hide_empty' => false ) ); | |
| 64 | - return join( $categories, PHP_EOL ); | |
| 67 | + $terms = get_terms( 'category', array( 'name__like' => $query, 'fields' => 'names', 'hide_empty' => false ) ); | |
| 68 | + return join( $terms, PHP_EOL ); | |
| 65 | 69 | } |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @param string $query | |
| 73 | + * | |
| 74 | + * @return string | |
| 75 | + */ | |
| 76 | + protected function list_tags( $query ) { | |
| 77 | + $terms = get_terms( 'post_tag', array( 'name__like' => $query, 'fields' => 'names', 'hide_empty' => false ) ); | |
| 78 | + return join( $terms, PHP_EOL ); | |
| 79 | + } | |
| 80 | + | |
| 66 | 81 | |
| 67 | 82 | /** |
| 68 | 83 | * @param string $query |
| 69 | 84 | * |