I’m looking for help as I’m building a query loop in which I identify the name of a cpt’s category. Where I’m stuck is that I also would like to display the number of posts inside that category. Unfortunately, no matter what I do I can’t get this to work.
If anyone could let me know how to do this, that would be great !
Cheers,
Franck.
A few weeks ago I wrote a php program to show the amount of posts in my custom post type.
You can add the code below in a code widget in Bricks. Change the post type and modify the query arguments as needed, i.e. enter the name of the category.
<?php
$args = array(
'post_type' => 'write here the post type',
'post_status' => 'publish',
'category_name' => 'write here your category name',
'cache_results' => false);
$loop = new WP_Query( $args );
echo "Total Posts found: ".$loop ->found_posts;
?>
You will find all information about this function here:
Thanks for the code. I forgot to mention I’m using bricks builder query loop tool to display cards on the website. I’m not sure if I can put this code inside the tool.
In case you want to show the count for different post types on different pages, you can use my other code because that one works without having to define a post type in the function.
All the parameters are defined directly within the Bricks query loop and not in the function itself.
To display the number of posts inside a CPT category in a query loop, use the wp_count_posts() function along with the category ID to fetch and display the count. Ensure your query loop correctly identifies the category before calling this function.
for more visit this website https://swigmenu.us/.