Use Variable for category_name
-
Hello,
I’ve got a page that determines the name of the child category that the current post belongs to:
<?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(3, $childcat)) { echo $childcat->cat_name ; }} ?>
Below this I’d like to show all other posts that also belong to this current child category.
<?php global $post; $args = array('category_name' => $childcat, 'posts_per_page' => -1, 'category__not_in' => 3,); $custom_posts = get_posts($args); foreach($custom_posts as $post) : setup_postdata($post); ?>
However, the
category_name' => $childcat
bit fails. If I type in the name or ID of the child category directly it works, but it needs to be a variable. What am I missing? Been Googling for about two hours trying to fix this. Not that well versed with WP it must be said.
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Use Variable for category_name’ is closed to new replies.