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!

1 Answer 1


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'));
  • 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
    Commented Apr 8, 2011 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
    Commented Apr 8, 2011 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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