Title: PHP variable equals post?
Last modified: August 19, 2016

---

# PHP variable equals post?

 *  [Jess](https://wordpress.org/support/users/jessn/)
 * (@jessn)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/php-variable-equals-post/)
 * Weird question. For various reasons I have a form script on a particular page
   that’s supposed to email the content of a couple different posts. I can’t seem
   to write it correctly though. I can get the post content to print on the page
   with:
 *     ```
       <?php $temp = $wp_query;
       $wp_query= null;
       $wp_query = new WP_Query();
       $wp_query->query('showposts=1&category_name=cat1'.'&paged='.$paged);
       ?>
       <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
       <?php the_title(); ?>
       <?php the_content(); ?>
       <?php endwhile; ?>
       <?php $wp_query = null; $wp_query = $temp;?>
       ```
   
 * But when I put that in the form code I get a horrible error. So I was wondering
   if there was some way I could save the title and the content in a PHP variable,
   and echo that variable into the email? Something like this (which doesn’t work):
 *     ```
       <?php $cat1 =
       $temp = $wp_query;
       $wp_query= null;
       $wp_query = new WP_Query();
       $wp_query->query('showposts=1&category_name=cat1'.'&paged='.$paged);
       ?>
       <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
       <?php the_title(); ?>
       <?php the_content(); ?>
       <?php endwhile; ?>
       <?php $wp_query = null; $wp_query = $temp;?>
       ```
   
 * And then in the actual email:
 * `<?php echo $cat1 ?>`
 * I’m able to echo more simple things in the form, but I don’t know how to pass
   the post content through. If anyone has suggestions for me I’d really appreciate
   it!

Viewing 1 replies (of 1 total)

 *  Thread Starter [Jess](https://wordpress.org/support/users/jessn/)
 * (@jessn)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/php-variable-equals-post/#post-1494400)
 * Found it. [http://www.velvetblues.com/web-development-blog/wordpress-post-variable-reference/#comment-5211](http://www.velvetblues.com/web-development-blog/wordpress-post-variable-reference/#comment-5211)

Viewing 1 replies (of 1 total)

The topic ‘PHP variable equals post?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Jess](https://wordpress.org/support/users/jessn/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/php-variable-equals-post/#post-1494400)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
