Count Posts in a Category, Tag, or Custom Taxonomy

Artiss README Parser: README file could not be found or is malformed - Count Posts in a Category

30 Thoughts on “Count Posts in a Category, Tag, or Custom Taxonomy

  1. redevolve on October 1, 2012 at 7:31 am said:

    Hi, can the plugin also count posts for a tag?

    • bitacre on October 2, 2012 at 11:36 pm said:

      It can now, I just pushed a new version (2.1) which has the tag="" argument. So you would use it just like the regular shortcode except you would replace cat="category-slug" with tag="tag-slug". You can also use IDs or names the same way if you specify a type="" argument.

      Thanks for the good idea!

      • Would love to have this for custom taxonomy as well…

        • bitacre on October 3, 2012 at 2:54 pm said:

          Haha, you guys are tough customers! This is easily doable, but I think the shortcode is going to get too confusing if I add any more attributes. I’ll tell you what, I’ll preserve the current functionality so nothing breaks, but I’ll add some additional shortcodes to make it less confusing. I will add

          [term_count taxonomy="custom-taxonomy-name" term="tax-slug/name/id" type="slug/name/id"]

          Because this will require the additional paramater of taxonomy=”custom-taxonomy-name”, I will put it in a separate shortcode.

          Or maybe I should just make a new one altogether…

          • adkhan on July 7, 2013 at 9:44 pm said:

            Hi, i wanna know how would you write the following shortcode in php

            [term_count taxonomy="custom-taxonomy-name" term="tax-slug/name/id" type="slug/name/id"]

  2. Hi,

    As we talked about via mail;

    It would be great to have a sum of all posts for a specific category, f.e. [tag_count id="45,85,34"] would give you a sum of all the posts in those categories.


    • bitacre on October 26, 2012 at 3:36 pm said:

      This feature is added as of version 3.1. It only works for IDs and slugs (since a name could ostensibly have a naturally occurring comma).

      Thanks for the great idea, I gave you credit in the readme.txt! :)

  3. I thought I had this working for me in a widget, but after deleting some other plugins today it no longer works. I can get the code to work for me inside a post, but not inside a widget. Should it be able to do both?


    • bitacre on October 26, 2012 at 3:07 pm said:

      Are you inserting the PHP function <?php do_shortcode( 'cat_count id="44"' ); ?> directly into the widget’s code; or are you just typing[cat_count id="44"] into a widget like you would in a post?

      By default, NO shortcodes will work inside of widgets or in comments. To make shortcodes work outside of posts and pages, you need to add the do_shortcode action to the relevant filter (in this case the widget_text filter).

      So either add the above listed PHP into your widget, or add this line to make ALL shortcodes work inside of the body of the text widget:

      add_filter( 'widget_text', 'do_shortcode' );

      • Awesome – thanks for the taking the time. Worked by adding the line into the theme functions and then [cat_count name="cat_name"] into the widget, though I couldn’t get the php line in the widget to render anything.

        • bitacre on November 10, 2012 at 3:10 pm said:

          You still won’t be able to paste PHP directly into the widget, just shortcodes, if that’s what you’re talking about.

          If you need to put PHP into the widget text, you’ll have to use your own callback function and hook it to the widget_text filter.

  4. bitacre on October 26, 2012 at 5:16 pm said:

    Including Future Posts

    This subpage explains how to include future (scheduled) posts in the count made by this plugin.

  5. hi, does this also work on custom post-types?

    im trying to get it to work for a custom post type categories, but it returns 0

    please help!

    • bitacre on November 29, 2012 at 9:34 pm said:

      Yes it does! You have to use the format

      [tax_count tax="taxonomy-name" slug="taxonomy-slug"]

      And replace the “taxonomy-name” with your custom category name and the “taxonomy-slug” with the slug of that custom category.

  6. Can I use this plugin to count posts that have a specific category AND a specific custom taxonomy value? Thanks!

  7. Labs Cilvēks on January 14, 2013 at 5:07 am said:

    Is it possible to insert counting of posts in WP 3.5 menu ?

    • bitacre on January 16, 2013 at 11:43 am said:

      You’ll have to enable the shortcode filter for menus in your theme, just wrap any section you want to be shortcode aware in the PHP code below. If you want it in your navigation menus, the simplest way is just to find wp_nav_menu( $args ) function wherever that appears in your theme (it may have an array inside of it or variable other than $args) and wrap it in the do_shortcode() function.

      < ?php do_shortcode( wp_nav_menu( $args ) ); ?>

      • rene on March 1, 2013 at 1:29 pm said:

        how to continue after I put the code < ?php do_shortcode( wp_nav_menu( $args ) ); ?>… Im lost and pulling my hair..

        sorry for maybe being dumb..

        thnks a lot!

        • bitacre on March 3, 2013 at 9:33 am said:

          (Dashboard) » Appearance » Editor

          or just append /wp-admin/theme-editor.php to your blog url while logged in.

  8. How do I get this plugin to work inside a text widget?

    • bitacre on January 25, 2013 at 11:48 am said:

      To make your Text widgets shortcode aware, you just need to add the do_shortcode() function to the widget_text filter. Just paste:

      add_filter( 'widget_text', 'do_shortcode' );

      somewhere in your theme’s functions.php file.

  9. Hombo on July 17, 2013 at 6:26 am said:

    Hi Luke,

    on the wordpress support forum for your plugin … here:

    you are posting a link to your support page… unfortunately it returns a 404 error.

    Might want to look into that.

    Hope it helps.

  10. Hombo on July 17, 2013 at 6:27 am said:

    I am not sure if this is implemented, if not please take this as a feature request.

    Can I “query” different categories with AND or OR relationsships?

    I see that you can do e.g.: [cat_count slug="cat-1,cat-2,cat-3"]

    But can i do: COUNT number of post in category 1 AND 2.. but NOT if they are category 3 ?

    This is something which would come handy for us as we have posts which are in multiple categories and we would like to filter out duplicate counts.

    An example of such “query syntax” can be seen on another plugin we are using ( it displays the posts in certain categories). Please go here:

    and you can see how the author implemented “Include AND”, “Include OR” and “Exclude” queries. Hope this helps.

    Can this perhaps be done already? if not would be great if you could consider this.

  11. I can’t get this to work. I’m using the shortcode in a post, and it’s returning a “0.”

  12. Danilo on October 4, 2013 at 9:51 pm said:

    Hi. It would be possible to add AND operator (+) for category count?

    Example: I need to count posts only if are presents in CATEGORY 1 [AND] CATEGORY 2. In WordPress, I can use + sign, but if I use with latest version of plugin, I get 0.

    It would be possible to add this feature?

  13. I am using the php code and it wont show up

  14. Had some trouble getting your “do_shortcode” example working, fixed it by changing to

  15. Hello!

    I would like to add a count in my site every catergory menu as You can see in here:

    Now it is manualy. Your plugin can help me?

    Sorry for my english!

    Thanks Zoltan

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>