Title: query_posts (category_name)
Last modified: August 19, 2016

---

# query_posts (category_name)

 *  [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/)
 * Hi.
 * In wp 2.6 i’ve used this codeline for view only post in the catergory:
    <?php
   query_posts(‘category_name=name on category’); ?>
 * This one doesn’t work in 2.7 version. Anyone know why?
 * BR,
    Alex

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

 *  [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-928964)
 * This appears to be a bug affecting child categories. Replace the spaces in the
   category with dashes to get around it for now.
 *  Thread Starter [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-928966)
 * filosofo:
    but i use query_posts(‘category_name=fashion&showposts=7’); now and
   it’s it doesn’t work.
 *  Thread Starter [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-928969)
 * It’s works with query_posts(‘page_id=7’); and query_posts(‘pagename=about’); 
   but not the cat or category_name. Strange! This worked in the 2.6 version. Should
   i downgrade the site to 2.6 again?
 *  Thread Starter [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929025)
 * there must be more users than me that uses this code on their pages? :S
 *  [Hiranthi](https://wordpress.org/support/users/illutic/)
 * (@illutic)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929026)
 * Well, to be honest: it is working for me.. I’m using it like this: `query_posts('
   cat=11,-7&showposts=5&orderby=rand');`
 *  Thread Starter [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929027)
 * Must test on a diffrent site…. strange!
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929028)
 * See possible fix on [http://trac.wordpress.org/ticket/8619](http://trac.wordpress.org/ticket/8619)
 *  Thread Starter [alex20hz](https://wordpress.org/support/users/alex20hz/)
 * (@alex20hz)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929040)
 * Ok I’ve no idea why this one doesnt work on the site. I checked with one other
   and test on a default theme and it worked!
 *  [Hiranthi](https://wordpress.org/support/users/illutic/)
 * (@illutic)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929052)
 * where are you using it in the other theme? (before/inside/after/instead of the
   loop?)
 *  [tardpress](https://wordpress.org/support/users/tardpress/)
 * (@tardpress)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929239)
 * This does seem to be a bug in 2.7.\*
 * It only affects category_name in query_posts when the category name has spaces
   in it e.g.:
 * `query_posts('category_name=Name of Category');`
 * **Filosofo**‘s response (above) is correct – changing the spaces to dashes solves
   this problem.
 * If you don’t know how to do this:
 *     ```
       $cat_name = 'Name of Category';
       $cat_name = str_replace(' ','-',$cat_name);
       query_posts('category_name='.$cat_name);
       ```
   
 *  [meylo](https://wordpress.org/support/users/meylo/)
 * (@meylo)
 * [17 years ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929260)
 * I’m having a similar problem I use
 * <?php query_posts(‘category_name=name on category’); ?>
 * It works fine, but It doesn’t include the post title and date.. any thoughts????
 *  [Marlimant](https://wordpress.org/support/users/marlimant/)
 * (@marlimant)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929278)
 * Replacing “category_name” by “cat_name” work for me.
 *  [Mike Castro Demaria](https://wordpress.org/support/users/mikecastrodemaria/)
 * (@mikecastrodemaria)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929300)
 * Marlimant, you save my day !
    Tanks

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

The topic ‘query_posts (category_name)’ is closed to new replies.

## Tags

 * [category_name](https://wordpress.org/support/topic-tag/category_name/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 8 participants
 * Last reply from: [Mike Castro Demaria](https://wordpress.org/support/users/mikecastrodemaria/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/query_posts-category_name/#post-929300)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
