Advertisement
pusatdata

Jumlah Post dari Sebuah Category atau Tags

Apr 19th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <?php
  2. $taxonomy = "category"; // can be category, post_tag, or custom taxonomy name
  3.  
  4. // Use any one of the three methods below
  5.  
  6. // Using Term ID
  7. $term_id = 1;
  8. $term = get_term_by('id', $term_id, $taxonomy);
  9.  
  10. // Using Term Name
  11. $term_name = 'A Category';
  12. $term = get_term_by('name', $term_name, $taxonomy);
  13.  
  14. // Using Term Slug
  15. $term_slug = 'a-category';
  16. $term = get_term_by('slug', $term_slug, $taxonomy);
  17.  
  18. // Fetch the count
  19. echo $term->count;
  20. ?>
  21.  
  22.  
  23. MODIFIKASI:
  24. Jumlah post dari sebuah tags, dimana tags otomatis dari sebuah tanggal.
  25.  
  26. <?php
  27. $taxonomy = "post_tag"; // can be category, post_tag, or custom taxonomy name
  28. // Using Term Name
  29. $term_name = get_the_date('Ymd');
  30. $term = get_term_by('name', $term_name, $taxonomy);
  31. // Fetch the count
  32. echo $term->count;
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement