0

I have two urls, and I want to know how many posts will be displayed there, when I click them. The goal is to show the visitor in the navigation of those urls, how many postings are found there.

As far as I can analyze those urls I would say it's about a category and then about a category and a tag. But pleas tell me if I am wrong.

Here are the two Urls, which actually end up in a blog-roll page (pseudo code):

http://site_url()/category/<category-name>/
and
http://site_url()/category/<category-name>/<tag-name>

while category is the string "category"

Is my question somehow clear?

Do I have to use count_posts() function?

1 Answer 1

2

You could run a new instantiation of WP_Query.

$query = new WP_Query([
    'category_name' => '<category_slug>',
    'tag'           => '<tag_slug>',
    'fields'        => 'ids', // To minimize the query, since we just need a count
]);

More on WP_Query

Then all you need to do is reference (integer) $query->found_posts.

Hope that helps. I don't think there is a better way unfortunately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.