Make a new WP_Query for the author’s posts in that category. The post count will be in WP_Query::post_count
https://developer.ww.wp.xz.cn/reference/classes/wp_query/
Thread Starter
Gustav
(@4ever16)
So i got this code but it prints result 0 why?
$user_id = get_the_author_meta('ID');
$args = array(
'author_name' => $user_id,
'category_name' => 'categoryname',
);
$wp_query = new WP_Query($args);
$posts = $wp_query->get_posts();
$my_count = count( $posts );
echo $my_count;
Thread Starter
Gustav
(@4ever16)
Ok so this code works now but why does it prints all posts in that category and never ends printing?
<?php
$user_id = get_the_author_meta('ID');
$args = array(
'author' => $user_id,
'category_name' => 'category-slug',
);
$wp_query = new WP_Query($args);
$posts = $wp_query->get_posts();
$my_count = count( $posts );
echo $my_count;
?>
Thread Starter
Gustav
(@4ever16)
Solved.
$user_id = get_the_author_meta('ID');
$args = array(
'author' => $user_id,
'category_name' => 'category_slug_name',
);
$my_query = new WP_Query( $args );
$my_count = $my_query->post_count;
echo $my_count;