Title: Quick PHP Question
Last modified: August 19, 2016

---

# Quick PHP Question

 *  Resolved [ralph23](https://wordpress.org/support/users/ralph23/)
 * (@ralph23)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/quick-php-question-3/)
 * Hey.
 * I’m using a query to show the latest post in the “Featured” category by using
   this code:
 *     ```
       <?php if (! is_paged()):
       	$my_query = new WP_Query('category_name=Featured&showposts=1');
       	$wp_query->in_the_loop = true;
       	while ($my_query->have_posts()) : $my_query->the_post();
       	$do_not_duplicate = $post->ID;
       ?>
       ```
   
 * Thing is, I want the user to be able to choose which category they want to be
   their “Featured” category. I have a variable (via Theme Options) with the correct
   category, thing is, I don’t know how to pass this variable into the query above,
   particularly this line right here:
 *     ```
       $my_query = new WP_Query('category_name=Featured&showposts=1');
       ```
   
 * I can’t put a variable in there because it’s surrounded with ‘ ‘. IF I remove
   the ‘ ‘, I get an error.
 * Any ideas?
 * Thanks.

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/quick-php-question-3/#post-956057)
 * `$my_query = new WP_Query('category_name=' . $featured_cat . '&showposts=1');`
 *  Thread Starter [ralph23](https://wordpress.org/support/users/ralph23/)
 * (@ralph23)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/quick-php-question-3/#post-956066)
 * Oh so thats what those annoying little periods are for…
 * Thanks Michael.
 *  [vanishdesign](https://wordpress.org/support/users/vanishdesign/)
 * (@vanishdesign)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/quick-php-question-3/#post-956355)
 * Using a variable for category_name in the WP_Query function call will shut down
   with two word category names. Your WP_Query will return no content if the category
   name is, say, “Web Design.”
 * I’m not sure how to get around it if you’re using the category name as the identifier.

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

The topic ‘Quick PHP Question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [vanishdesign](https://wordpress.org/support/users/vanishdesign/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/quick-php-question-3/#post-956355)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
