Custom WP_Query for current category (in category.php)?

I’m using a small code to display a tag list for the current categories like below:

<?php
$custom_query = new WP_Query('posts_per_page=-1&category_name=overnachten');
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            $all_tags[] = $tag->term_id;
        }
    }
endwhile;
endif;

$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);

$args = array(
'smallest'  => 12,
'largest'   => 12,
'unit'      => 'px',
'number'    => 0,
'format'    => 'list',
'include'   => $tags_str
);
wp_tag_cloud($args);
?>

It currently displays the tags used by the posts in one certain category. I want to use the above code to display all the tags from the category I’m currently in. How would this be possible, with the above code or a better way?

1 Answer
1

Try referencing the cat query variable like so:

$custom_query = new WP_Query( 
    array( 
        'cat' => get_query_var('cat') 
    ) 
);

Leave a Comment