Title: Query posts using category option
Last modified: August 19, 2016

---

# Query posts using category option

 *  [nemci7v](https://wordpress.org/support/users/nemci7v/)
 * (@nemci7v)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/)
 * I made a theme option to choose from which category to display posts on the homepage.
   The code is..
 *     ```
       <?php query_posts('cat=$theme_category&showposts=$theme_posts_number'); ?>
       		<?php while (have_posts()) : the_post(); ?>
       		<?php the_post_thumbnail( 'frontpage' ); ?>
       <?php endwhile ?>
       ```
   
 * I would think that $theme_category will call the number I put in the option but
   it doesn’t. I’m not sure what I’m doing wrong here..

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

 *  Thread Starter [nemci7v](https://wordpress.org/support/users/nemci7v/)
 * (@nemci7v)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392509)
 * update:
 * I tried `<?php echo $theme_category;?>`
 * but it retrieves all the posts from every category instead the one I put in options.
   hmm..
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392510)
 * Where are you calling this theme option from the database?
 *  Thread Starter [nemci7v](https://wordpress.org/support/users/nemci7v/)
 * (@nemci7v)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392518)
 * From the functions.php using the
 *     ```
       $themename = "Theme Name";
       $shortname = "theme";
       $options = array (
       ...
       ```
   
 * technique
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392544)
 * Is this a theme option as in the user can enter a category name or id and have
   that option saved? Or are you just setting up a variable in functions.php? If
   it’s the latter, why not just add it to the template?
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392571)
 * Use double quotes in your query posts line and the variables will work..
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392574)
 * Oh well spotted! (new cat?)
 * `<?php query_posts('cat=' . $theme_category . '&showposts=' . $theme_posts_number);?
   >`
 * should work too.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392610)
 * Figured the double quotes would be easier … less to explain …
 * Same cat, different pic.. 🙂
 *  Thread Starter [nemci7v](https://wordpress.org/support/users/nemci7v/)
 * (@nemci7v)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392659)
 * Thank you!! Both solutions worked 🙂
 * Nice new cat pic 🙂

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

The topic ‘Query posts using category option’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [nemci7v](https://wordpress.org/support/users/nemci7v/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/query-posts-using-category-option/#post-1392659)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
