You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// do nothing if supplied 'q' parameter is omitted or empty
29
35
// or less than 2 characters long
30
36
if (empty($q) || strlen($q) < 2) {
31
-
die();
37
+
wp_die();
32
38
}
33
39
34
40
switch ($type) {
@@ -51,7 +57,7 @@ public function ajax(): void
51
57
break;
52
58
}
53
59
54
-
die();
60
+
wp_die();
55
61
}
56
62
57
63
/**
@@ -64,13 +70,15 @@ protected function list_posts($query, $post_type = 'post')
64
70
{
65
71
global$wpdb;
66
72
$like = $wpdb->esc_like($query) . '%';
73
+
$limit = self::MAX_RESULTS;
67
74
68
75
$post_slugs = $wpdb->get_col(
69
76
$wpdb->prepare(
70
-
"SELECT p.post_name FROM $wpdb->posts p WHERE p.post_type = %s AND p.post_status = 'publish' AND ( p.post_title LIKE %s OR p.post_name LIKE %s ) GROUP BY p.post_name",
77
+
"SELECT p.post_name FROM $wpdb->posts p WHERE p.post_type = %s AND p.post_status = 'publish' AND ( p.post_title LIKE %s OR p.post_name LIKE %s ) GROUP BY p.post_name ORDER BY p.post_name ASC LIMIT %d",
71
78
$post_type,
72
79
$like,
73
-
$like
80
+
$like,
81
+
$limit
74
82
)
75
83
);
76
84
returnjoin(PHP_EOL, $post_slugs);
@@ -86,9 +94,15 @@ protected function list_categories($query)
86
94
$terms = get_terms([
87
95
'taxonomy' => 'category',
88
96
'name__like' => $query,
97
+
'number' => self::MAX_RESULTS,
89
98
'fields' => 'names',
90
99
'hide_empty' => false,
91
100
]);
101
+
102
+
if (is_wp_error($terms)) {
103
+
return'';
104
+
}
105
+
92
106
returnjoin(PHP_EOL, $terms);
93
107
}
94
108
@@ -102,9 +116,15 @@ protected function list_tags($query)
102
116
$terms = get_terms([
103
117
'taxonomy' => 'post_tag',
104
118
'name__like' => $query,
119
+
'number' => self::MAX_RESULTS,
105
120
'fields' => 'names',
106
121
'hide_empty' => false,
107
122
]);
123
+
124
+
if (is_wp_error($terms)) {
125
+
return'';
126
+
}
127
+
108
128
returnjoin(PHP_EOL, $terms);
109
129
}
110
130
@@ -124,6 +144,8 @@ function ($name) use ($query) {
0 commit comments