Can not concatenate WordPress function to query string
-
On my page the_category()displays the name of the current category the user has clicked on, I want to use this and pass it into my function to display the tags in the current category. The function works if you manually type in the category name.
I have tried to concatenate the the_category()to the end of the query string but this doesn’t work and just prints out all the tags in the blog.
<div class="heading"><h1>Category:<?php the_category(); ?></h1></div> <?php $custom_query = new WP_Query('posts_per_page=-1&category_name=' .the_category());//This will work if I enter ='cheese' for example 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;
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Can not concatenate WordPress function to query string’ is closed to new replies.