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

$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;

$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

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?

  • Can I ask what the purpose of this is? It sounds like this is a problem you have with a solution to yet another problem that you haven't mentioned, and that there may be a far better/faster/easier way to do what you're trying to accomplish
    – Tom J Nowell
    Commented Dec 3, 2014 at 1:53

1 Answer 1


Try referencing the cat query variable like so:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.