Title: Using a variable to pull posts from category
Last modified: August 19, 2016

---

# Using a variable to pull posts from category

 *  [egbmike](https://wordpress.org/support/users/egbmike/)
 * (@egbmike)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/)
 * Hi,
 * Per this article [http://codex.wordpress.org/Template_Tags/query_posts](http://codex.wordpress.org/Template_Tags/query_posts)
   I am trying to pull posts from a category using the category name, but I am trying
   to use a php variable generated elsewhere to insert the name of the category.
   So my code looks like:
 * query_posts(‘category_name=$variable’);
 * But this isn’t working. Can anyone help?
 * Thanks,
    Mike

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109866)
 * Where are you trying to use this? What template?
 * Related:
 * [Stepping Into Templates](http://codex.wordpress.org/Stepping_Into_Templates)
   
   [Template Hierarchy](http://codex.wordpress.org/Template_Hierarchy)
 *  Thread Starter [egbmike](https://wordpress.org/support/users/egbmike/)
 * (@egbmike)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109971)
 * It is the Revolution Pro theme but I don’t think this is a theme issue, it is
   more of how do you insert a PHP variable inside a WordPress statement, correct?
   For reference the site is [http://www.europeupclose.com](http://www.europeupclose.com).
 * Thanks,
    Mike
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109972)
 * But where you want to use that variable? On your main blog page? Or in a [{Category
   Templates|Category Template]], or a date based archive, or a single post view?
 * Please review [Template Hierarchy](http://codex.wordpress.org/Template_Hierarchy)
   if necessary. You will also want to review [Stepping Into Template Tags](http://codex.wordpress.org/Stepping_Into_Template_Tags)
   and [Stepping Into Templates](http://codex.wordpress.org/Stepping_Into_Templates)
   if you are going to modify a theme to do ‘things’.
 *  Thread Starter [egbmike](https://wordpress.org/support/users/egbmike/)
 * (@egbmike)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109976)
 * Oh sorry I misunderstood your question, I primarily want to use it on archive.
   php.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109978)
 * You do understand that WordPress automatically will provide you access to category
   type archives if you assign categories to posts?
 * If you are talking about a date based archive, then how is that dynamic category
   variable discovered?
 * Oh well, probably not understanding you so will point you to [Category Templates](http://codex.wordpress.org/Category_Templates).

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

The topic ‘Using a variable to pull posts from category’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 12 months ago](https://wordpress.org/support/topic/using-a-variable-to-pull-posts-from-category/#post-1109978)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
