我正在尝试按指定的第一个字符获取类别列表。
例如,如果指定的字符查询是“A”,那么只想列出以“A”开头的类别。
怎么可能呢?
我正在尝试按指定的第一个字符获取类别列表。
例如,如果指定的字符查询是“A”,那么只想列出以“A”开头的类别。
怎么可能呢?
global $wpdb; // In case it\'s in a function...
$parent = 0; // Change to dig deeper in tree
$wpdb->query(
<<<SQL
SELECT
t1.`term_id`, /* The ID */
t1.`name`, /* The name */
t1.`slug`, /* The slug */
t2.`parent`, /* The parent ID */
t2.`count` /* The item Count */
FROM
{$wpdb->terms} AS t1,
{$wpdb->term_taxonomy} AS t2
WHERE
(t1.`term_id` = t2.`term_id`) /* Join tables on term_id */
AND (t2.`taxonomy` = \'category\') /* Make sure we get category taxonomy */
/* Change parent (remove) according to your needs to dig deeper */
AND (t2.`parent` = {$parent}) /* Remove to get all, not just top level */
/* Remove the BINARY for case-insensitive comparison (both A and a) */
AND (t1.`name` LIKE BINARY \'A%\');
SQL
);
跟随评论当做
我正在使用wp_dropdown_categories() 输出下拉列表。在默认视图中(未单击),它显示列表中第一个类别的名称。我想说的是“类别”。这可能吗?提前感谢