I made some debugging …
Inside widgets.php we have the function:
private function generate_lists( $taxonomies, $data )
the the get_terms function returns the correct number of posts …
$terms = $this->get_terms( $taxonomy );
but the walker mess up with the count inside:
$data_tax = array(
'taxonomy' => $taxonomy,
'title' => get_taxonomy( $taxonomy )->label,
'term-list' => $walker->walk( $terms, 0 )
);
I dont know how the Walker class works … If anyone can help ?
Another question: Is there a way to remove the terms that do not have any posts?
More debugging …
It seens the problem is in walkers.php:
QMT_Data_Container
function count() {
$old_query = qmt_get_query();
if ( $this->data['is-selected'] ) {
return $GLOBALS['wp_query']->post_count;
}
// Considering previous choices
if ( isset( $old_query[ $this->taxonomy ] ) ) {
$query = $old_query;
$query[$this->taxonomy] = $query[$this->taxonomy] . "+" . $this->term->slug;
} else {
$query = array_merge( $old_query, array( $this->taxonomy => $this->term->slug ) );
}
return QMT_Count::get( $query );
}
I dont know how to fix the query, the query that is being generate is:
SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC
Ok … I made a patch to walkers.php the counter is working for categories. I did not test with multiple taxonomies.
Replace function count() inside class QMT_Data_Container for this:
function count() {
$old_query = qmt_get_query();
if ( $this->data['is-selected'] ) {
return $GLOBALS['wp_query']->post_count;
}
$query = array(
'tax_query' => array(
'relation' => 'AND'
)
);
// Considering previous choices
if ( isset( $old_query[ $this->taxonomy ] ) ) {
$terms = explode('+', $old_query[ $this->taxonomy ]);
$terms[] = $this->term->slug;
} else {
$terms = $this->term->slug;
}
$query['tax_query'][] = array (
'taxonomy' => $this->taxonomy,
'field' => 'slug',
'terms' => $terms,
'include_children' => 0,
'operator' => 'AND'
);
return QMT_Count::get( $query );
}
Now, how do I remove the categories that do not have posts ?
Plugin Author
scribu
(@scribu)
That seems to work. Commited:
https://github.com/scribu/wp-query-multiple-taxonomies/commit/9a1120dcbe11955e78d3fa95c3a354eb96411243
Now, how do I remove the categories that do not have posts ?
That should already be handled in QMT_Terms::get()
.
I do not recommend trying to remove parent categories that have non-empty child categories.