Title: Post Counter Short Code
Last modified: August 24, 2016

---

# Post Counter Short Code

 *  [Buddypressnewb](https://wordpress.org/support/users/nunivo/)
 * (@nunivo)
 * [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/)
 * Greetings,
 * I am still a greenie on PHP coding, how can i make a short code that counts the
   numbers of post (all post)?
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [schulte](https://wordpress.org/support/users/schulte/)
 * (@schulte)
 * [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/#post-6095198)
 * Nunivo,
 * What exactly are you trying to accomplish? Display the total amount of published
   posts?
 *  Thread Starter [Buddypressnewb](https://wordpress.org/support/users/nunivo/)
 * (@nunivo)
 * [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/#post-6095212)
 * [@schulte](https://wordpress.org/support/users/schulte/)
 * I am busy with job site that counts the active jobs and resumes. I also want 
   something that counts the number of post (articles).
 * The theme that i use supports short codes (on the frontpage), for the above the
   theme developer made a short code. But a counter for post is behind their support(
   that’s understandable).
 * A fuction code that generates this short code, would solve my problem.
 * Thank you.
 *  [schulte](https://wordpress.org/support/users/schulte/)
 * (@schulte)
 * [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/#post-6095216)
 * Nunivo,
 * Place the following at the end of your themes `functions.php` file and then add
   something like `Number of Posts: [post_count]` on your post or page to display
   the number of published posts.
 *     ```
       function my_post_count() {
       	$count_posts = wp_count_posts();
       	$published_posts = $count_posts->publish;
   
       	return $published_posts;
       }
       add_shortcode('post_count', 'my_post_count');
       add_filter('my_post_count', 'do_shortcode');
       /* End Shortcode Post Count [post_count] */
       ```
   
 * lifted from from [Digital Raindrops](http://profiles.wordpress.org/users/Adeptris/):
   [https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post](https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post)
 *  Thread Starter [Buddypressnewb](https://wordpress.org/support/users/nunivo/)
 * (@nunivo)
 * [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/#post-6095236)
 * [@schulte](https://wordpress.org/support/users/schulte/)
 * Many thanks a friend of my helped me with adjusting the code, this is code that
   he gave me:
 * function my_post_count() {
    $count_posts = wp_count_posts(); $published_posts
   = $count_posts->publish;
 *  return $published_posts;
    } add_shortcode(‘my_post_count’, ‘my_post_count’);
 * Thanks for the help.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Post Counter Short Code’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [Buddypressnewb](https://wordpress.org/support/users/nunivo/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/post-counter-short-code/#post-6095236)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
