Parent category (1)
├ Child category A (1)
│ ├ Grandchild category A01 (1)
│ └ Grandchild category A02 (2)
└ Child category B (1)
. └ Grandchild category B01 (2)
The content in parentheses is the number of articles posted.
Given the structure above, I would like to see only the number of posts in the grandchild category on the archive page.
$term_id = parent category ID; $term = get_term_by ('id', $term_id,'category'); echo $term->count;
I put the above code to refer to get_term_by.
I thought that "7" including the child category would be returned, but the value returned is "0".
Ultimately, I want to get only the number of posts in the grandchild category, but is there a reason why I can't get the number of posts with get_term_by?
Answer # 1
get_term_by ()I think that only items with the parent category ID will be returned.
In the example of your question, "1" should be returned. I think you need to confirm that "0" is returned.
$args = array ( 'parent' =>Parent category ID ); $terms = get_terms ('category', $args);
Child category A,
Child category BBecause the term is set,
In the same way (loop processing as appropriate),
$args = array ( 'parent' =>$terms->term_id // parent is child category A ); $terms = get_terms ('category', $args);
How about the procedure of totaling as?
- php - please tell me how to display the total number of refined searches
- php - double list of custom posts
- php - display the term list and attach a class to those linked to the post
- i want to check the form input with php, display an error on the same page if it is not filled in, and move to another page only
- php - csv download of data cannot download when the number of columns increases
- php - [wordpress] i want to display the "new mark" in the navigation when there is a new article
- php - i can't click the number of pages in the page view
- php - cannot display the value of the many-to-many relationship destination table in view
- php - i want to display an error or redirect
- php - how to loop with undecided number of times
- php - i want to output the page number 01 02 03 with pagination paginate_links
- php - "display option" is not displayed in the post list on the wordpress administration screen
- php - i want to get the number of users who are following laravel and the number of users who are being followed by using count
- [php/laravel] i want to display all of a large amount of dom
- i want to display a one-dimensional vector from the number entered with the python keyboard to 0
- ruby on rails - i want to display the number of people in the group
- php - i want to display checkbox items for custom fields
- php - i want to display a list of articles that belong to both the current term and the term shared in the cpt ui
- php : Cancel the output of a certain category from the_terms
- php : CONTACT FORM 7 does not display notifications when sending a letter
- php : The problem with the WordPress Navxt plugin when useing Polylang
- php : Help Write the Cable for Links to Image
- php : AJAX Search for WordPress
- php : How to transfer the value of a variable in t.slug in ()?
- php : How to make comments in custom recordings?