WordPress 根据第一个字母列出分类

本主题由 隐藏人物 创建于 2016-3-28 22:23:13

List Categories By Specified First Character
http://wordpress.stackexchange.com/questions/32477/list-categories-by-specified-first-character

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
);

放心注册,GeeKaa不会虚耗你半点时间,你只会发现更多乐趣。 立即注册