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

Okay, I think I'm pretty close. I have the following going on:

$cat_id = get_cat_id('library');


However, it doesn't work with $cat_id in there. It does work when I put the category's ID number in there (which I got when I echoed $cat_id), but obviously that presents a problem when I install the site on the real server. What should I try? Thanks!

share|improve this question
up vote 1 down vote accepted

If you change your single quote marks in to double quote marks it should work :

$cat_id = get_cat_id('library');

but if you really want to make it more flexible you can phrase your arguments as an array:

$args = array(
 'hierarchical' => 1,
 'parent' => get_cat_id('library'));

and if you want to make it even more flexible to get the current category's children you can use get_query_var('cat'); assuming that you are in your category.php file, so:

$args = array(
 'hierarchical' => 1,
 'parent' => get_query_var('cat'));
share|improve this answer
The PHP manual has more info about the difference between single and double quoted strings. Basically it boils down to the fact that a $ in a single quoted string will not indicate a variable, so your $cat_id stays $cat_id, not 11 or whatever the category ID might be. – Jan Fabry Apr 8 '11 at 9:02
Doh! I can't believe I forgot to concatenate that variable. No wonder I felt like it's worked before. Thank you very much for answering my dumb question. Also, I didn't know about the double-quote trick before. – Webkohder Apr 8 '11 at 16:46

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.