When I use get_categories()
in the archive.php file, having hide_empty activated (true|1), and then sending a year value to the file. The hide_empty argument lost it's effect. Categories that doesn't have posts from the selected year shows anyway.
How do I get the categories to be hidden if it doesn't has posts connected from the selected year?
Edit: My code:
<?php
if (!empty($_GET['m']))
{
?>
<h2><?php echo _e('Categories'); ?></h2>
<ul>
<?php
foreach(get_categories('parent=0&hide_empty=1') as $category)
{
$my_query = new WP_Query('cat='.$category->term_id.'&year='.$_GET['m'].'&posts_per_page=-1');
$count = $my_query->post_count;
?>
<li><a class="name" href="?cat=<?=$category->term_id?>&year=<?=$_GET['m']?>"><?=$category->name?> (<?=$count?>)</a></li>
<?php
$cats = get_categories('parent='.$category->term_id.'&year='.$_GET['m'].'&hide_empty=1');
if (count($cats))
{
?>
<ul>
<?php
foreach($cats as $category)
{
$my_query = new WP_Query('cat='.$category->term_id.'&year='.$_GET['m'].'&posts_per_page=-1');
$count = $my_query->post_count;
?>
<li><a class="name" href="?cat=<?=$category->term_id?>&year=<?=$_GET['m']?>"><?=$category->name?> (<?=$count?>)</a></li>
<?php
}
?>
</ul>
<?php
}
}
?>
</ul>
<?php
}
?>