Dynamic Web Lab
Back to insights

Get custom post count in custom taxonomy

October 31, 20131 min read

To get total custom post count of a custom taxonomy use the follow code
[php]
$args = array(
‘post_type’ => ‘post type name here’,
‘post_status’ => ‘published’,
‘taxonomy name here’ => ‘slug of the category under taxonomy’,
‘numberposts’ => -1
);
echo $num = count( get_posts( $args ) );
[/php]

For instance, if you had a custom taxonomy called “product_category” and wanted to only show posts from the “manes” product_category you would use the below code.

[php]
$args = array(
‘post_type’ => ‘product’,
‘post_status’ => ‘published’,
‘product_category’ => ‘manes’,
‘numberposts’ => -1
);
echo $num = count( get_posts( $args ) );
[/php]

Writer

Dynamic Web Lab Editorial

We share how we design, engineer, and scale digital products across the GCC, Europe, and the US.

Share this article

Need help implementing this?

We turn these playbooks into shipped features. Let us scope your roadmap and support your team.

Start a project conversation
Get custom post count in custom taxonomy - Demo Dynamic Web Lab