• Resolved tiagoalves83

    (@tiagoalves83)


    Hi,

    I am not using custom taxonomies, just default hierarchy category. WP 3.4.1 and QMT 1.6.1
    Right now, I have 3 categories and 4 posts:

    Post 1 – Category A, Category A1 (sub-category)
    Post 2 – Category A, Category B
    Post 3 – Category B
    Post 4 – Category B

    When I add Taxonomy Drill-Down widget to my sidebar I get:

    Category A (3)
    – Category A1 (3)
    Category B (3)

    It suppose to be:
    Category A (2)
    – Category A1 (1)
    Category B (3)

    right ?

    If I choose “Category A” I get:
    Category A (2)
    – Category A1 (3)
    Category B (3)

    It suppose to be:
    Category A (2)
    – Category A1 (1)
    Category B (1)

    right ?

    If someone can help. Thanks.

    http://wordpress.org/extend/plugins/query-multiple-taxonomies/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tiagoalves83

    (@tiagoalves83)

    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?

    Thread Starter tiagoalves83

    (@tiagoalves83)

    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

    Thread Starter tiagoalves83

    (@tiagoalves83)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Query Multiple Taxonomies] wrong posts count’ is closed to new replies.