Title: inserting a variable&#039;s value into a post
Last modified: August 20, 2016

---

# inserting a variable's value into a post

 *  [tsolignani](https://wordpress.org/support/users/tsolignani/)
 * (@tsolignani)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post/)
 * Is there a way to?
 * F.i., say I would like to write into a post something like «we have xxx posts
   as of today», where xxx should be a value of a variable?
 * Thank you.

Viewing 1 replies (of 1 total)

 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post/#post-2269463)
 * The ways I can think of to do this would be a plugin that allows [php code to be written into the posts](http://wordpress.org/extend/plugins/search.php?q=Post+PHP&sort=).
 * There are some, but none I can see that look to have been updated for over a 
   year.
 * The other is to create a function of your own in functions.php which will allow
   you to add a shortcode to the posts.
 * Then use [wp_count_posts()](http://codex.wordpress.org/Function_Reference/wp_count_posts)
 * **Untested Function WARNING:**
    This code should not be tested on a production
   website only test on a local install.
 *     ```
       function my_post_count() {
       	$count_posts = wp_count_posts();
       	$published_posts = $count_posts->publish;
   
       	return 'we have ' .$published_posts. 'posts as of today';
       }
       add_shortcode('post_count', 'my_post_count');
       add_filter('my_post_count', 'do_shortcode');
       /* End Shortcode Post Count [post_count] */
       ```
   
 * In the post you would use a shortcode
 * Did you know that [post_count], why not check out some of the others?
 * HTH
 * David

Viewing 1 replies (of 1 total)

The topic ‘inserting a variable's value into a post’ is closed to new replies.

## Tags

 * [post](https://wordpress.org/support/topic-tag/post/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post/#post-2269463)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
