Title: Have function add variables/values to the $post object?
Last modified: August 19, 2016

---

# Have function add variables/values to the $post object?

 *  [mattloak](https://wordpress.org/support/users/mattloak/)
 * (@mattloak)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/have-function-add-variablesvalues-to-the-post-object/)
 * How do I add `$tzDesc` and `$tzEmbed` (and other variables) to the $post object
   in the following function so that I can display the values in my theme files 
   by inserting `<?php echo $tzDesc; ?>`?
 *     ```
       add_action( 'the_post', 'paginate_slide' );
   
       function paginate_slide( $post ) {
   
           global $pages, $multipage, $numpages;
   
           if( is_single() && get_post_type() == 'post' ) {
   
           $multipage = 1;
           $id = get_the_ID();
           $custom = array();
           $pages = array();
           $i = 1;
   
           foreach( get_post_custom_keys() as $key )
               if ( false !== strpos( $key, 'slide' ) )
                   $custom[$key] = get_post_meta( $id, $key, true);
   
           while( isset( $custom["slide{$i}-title"] ) ) {
   
               $page = '';
               $tzTitle = $custom["slide{$i}-title"];
               $tzImage = $custom["slide{$i}-image"];
               $tzDesc = $custom["slide{$i}-desc"];
               $tzEmbed = $custom["slide{$i}-embed"];
   
               $page = "<h2>{$tzTitle}</h2><img src='{$tzImage}' />";
               $pages[] = $page;
               $i++;
           }
   
           $numpages = count( $pages );
           }
       }
       ```
   

The topic ‘Have function add variables/values to the $post object?’ is closed to
new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [mattloak](https://wordpress.org/support/users/mattloak/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/have-function-add-variablesvalues-to-the-post-object/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
