WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get category list by specified first character.

For example if specified character query is "A", then just wanna list categories start with "A".

How is it possible?

share|improve this question
global $wpdb; // In case it's in a function...
$parent = 0; // Change to dig deeper in tree
        t1.`term_id`, /* The ID */
        t1.`name`, /* The name */
        t1.`slug`, /* The slug */
        t2.`parent`, /* The parent ID */
        t2.`count` /* The item Count */
        {$wpdb->terms} AS t1,
        {$wpdb->term_taxonomy} AS t2
        (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%');

Follow the comments.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.