So I'm having trouble printing just the direct children of a category on a page. Here's my code:
$category_id = get_cat_ID('destinations'); $args = array('child_of' => $category_id); $categories = get_categories($args); $args = array ( 'category__and' => $categories->$cat_ID ); $recent_posts = new WP_Query($args); if ($recent_posts->have_posts()) : while ($recent_posts->have_posts()) : $recent_posts->the_post();
This code prints every category regardless of who's the parent. If I change this:
$recent_posts = new WP_Query('cat=43'); It prints out the right category, but also all of it's children and children's children(obviously). I just want the directly related children printed. I went ahead and echoed a serialize($categories) which returned the correct array. However when I serialize($args) AFTER the 2nd declaration, it gives me:
This is definitely weird. Why on Earth is it returning an 'N' for $categories->$cat_ID? I've been trying to do this all day and have been unsuccessful. I've also tried to find another method to do what I want but nothing came up.