Advertisement
pusatdata

WP Trik: Show Post Count in Category Custom Menu

May 30th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Source:
  2. https://gist.github.com/generatepress/050648ac7d2d566865ac
  3.  
  4.  
  5.  
  6. Paste this code in function:
  7.  
  8. add_filter('the_title', 'generate_category_post_count_title', 10, 2);
  9. function generate_category_post_count_title($title, $post_ID)
  10. {
  11. if( 'nav_menu_item' == get_post_type($post_ID) )
  12. {
  13. if( 'taxonomy' == get_post_meta($post_ID, '_menu_item_type', true) && 'category' == get_post_meta($post_ID, '_menu_item_object', true) )
  14. {
  15. $category = get_category( get_post_meta($post_ID, '_menu_item_object_id', true) );
  16. $title .= sprintf(' (%d)', $category->count);
  17. }
  18. }
  19. return $title;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement