Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

$cat_id = get_cat_id('library');

wp_dropdown_categories('hierarchical=1&parent=$cat_id');

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
add comment

1 Answer

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');
wp_dropdown_categories("hierarchical=1&parent=$cat_id");

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'));
wp_dropdown_categories($args);

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'));
wp_dropdown_categories($args);
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
add comment

Your Answer

 
discard

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.