jcpeden Posted June 21, 2011 Share Posted June 21, 2011 I'm working on a custom category page for a Wordpress theme and I need to pass (correct me if that is the wrong terminology) to an argument for the function get_categories: if (is_category('4,6,9')) { ?> <?php $categories = get_categories("child_of=$cat-id"); foreach ($categories as $cat) { query_posts("cat=$cat->cat_ID&showposts=-1&order=ASC&orderby=name"); I would like $cat-id to be either 4, 6 or 9 depending on which category page the user is looking at. How do I make this happen? Link to comment https://forums.phpfreaks.com/topic/239974-how-to-pass-a-variable-to-a-function-as-an-argument/ Share on other sites More sharing options...
trq Posted June 21, 2011 Share Posted June 21, 2011 To start within, $cat-id is not a valid PHP variable. The rest of your question doesn't really make allot of sense. Simply assign whatever value you need depending on whatever condition you need. Link to comment https://forums.phpfreaks.com/topic/239974-how-to-pass-a-variable-to-a-function-as-an-argument/#findComment-1232703 Share on other sites More sharing options...
jcpeden Posted June 21, 2011 Author Share Posted June 21, 2011 Here is what I've come up with. I've tested this code and the results are absolutely perfect for what I need. As I'm pretty much a beginner with PHP, please let me know if I've gone about it in an a$$ backward manner. // Get current category id and concatenate argument 'child_of=cat_id' function child_categories(&$current_cat_ID) { global $wp_query; $current_cat_ID .= get_query_var('cat'); } $child_of = 'child_of='; child_categories($child_of); // Get child categories of current category $categories=get_categories($child_of); Apologies if I've explained myself badly Link to comment https://forums.phpfreaks.com/topic/239974-how-to-pass-a-variable-to-a-function-as-an-argument/#findComment-1232882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.