• Hi,

    I need to display something like this on my custom taxonomy archive page:
    Number of items: x, where x is the post count on the current page.

    I have 3 “categories” in my custom taxonomy and each of them have an individual “archive page”

    What code should I put in my taxonomy-taxonomyname.php file?

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Brent

    (@illegit)

    More info:

    I’m displaying ALL posts on one page so x = total number of posts in that certain category.

    You can try this generic function that I re-use in my projects. I hope this helps.

    <?php
    function get_custom_taxonomy_count($post_type, $tax_term, $taxonomy_name) 
    
    {
    
    	$taxonomy = 'my_taxonomy'; // this is the name of the taxonomy
    
        $args = array(
    
            'post_type' => $post_type, 'posts_per_page' => '1',
    
    		'meta_query' => array(
    
    				array(
    
    					'key' => 'closed',
    
    					'value' => '0',
    
    					'compare' => '='
    
    				)
    
    			),		
    
            'tax_query' => array(
    
                        array(
    
                            'taxonomy' => $taxonomy_name,
    
                            'field' => 'slug',
    
                            'terms' => $tax_term)
    
                    )
    
            );
    
         $my_query = new WP_Query( $args );
    
    	 return $my_query->found_posts;
    
    }
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘getting total post count of custom post type in custom taxonomy?’ is closed to new replies.