Title: query_posts not pulling category_name.
Last modified: August 19, 2016

---

# query_posts not pulling category_name.

 *  Resolved [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * (@hedgomatic)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/)
 * I’m creating a publication plugin & theme that organizes posts into volumes and
   issues, like a magazine or newspaper.
 * My plugin sets both an active issue, and an “upcoming” issue that is only viewable
   by the admin. All posts receive several categories: “Live” (aka: publicly viewable),“
   Submitted” (offline, admin-viewable) and the volume and issue in the following
   format: Volume#_Issue#
 * So, in my admin logic, I’m querying for the next volume and issue options from
   my plugin:
 * if (current_user_can(‘manage_options’)) {
    $Volume = get_option( $opt_nextVolume_name);
   $Issue = get_option( $opt_nextIssue_name );
 * and then putting them together:
 * $VolumeAndIssue = ‘Volume’.$Volume.’_Issue’.$Issue;
 * Then I look for posts with this category:
 * if (is_home()) { query_posts(‘category_name=’.$VolumeAndIssue); } else { query_posts(‘
   category_name=Live’); }
 * However if(have_posts()) returns false, and query_posts returns an empty array.
 * Spitting out the value of $VolumeAndIssue, I see that it’s set to Volume1_Issue3(
   which is correct)
 * I have a single post with some lorem ipsum text marked with this category.
 * I’ve double-checked for any typos or case-sensitive errors.
 * Any advice on how I can better debug the problem?

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

 *  Thread Starter [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * (@hedgomatic)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/#post-1374321)
 * [here’s a screeshot of the post](http://www.awayfromkeyboard.com/volume_issue.gif)
   that should be pulled by the logic above.
 * Here’s the relevant code all in one chunk:
 *     ```
       <?php
       if (current_user_can('manage_options')) {
       	$is_admin = true;
       	$Volume = get_option( $opt_nextVolume_name );
       	$Issue = get_option( $opt_nextIssue_name );
       	$VolumeAndIssue = 'Volume'.$Volume.'_Issue'.$Issue;
       	if (is_home()) { query_posts('category_name='.$VolumeAndIssue); } else { query_posts('category_name=Live'); }
       } else {
       // not logged in query, etc
       }
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       		<? /*** CUSTOM THEME OPTIONS FOR THE ISSUE ***/ ?>
       		<?php include(TEMPLATEPATH.'/'.$VolumeAndIssue.'.php'); ?>
       		<?php the_content(__('(more...)')); ?>
       <?php endwhile; else: ?>
       	<p><?php _e("Sorry, we couldn't find what you were looking for."); ?></p>
       <?php endif; ?>
       ```
   
 * **Returns:**
 * _“Sorry, we couldn’t find what you were looking for.”_
 * **Update:** If I remove the query_post(), thereby getting all my published posts,
   and then try:
 * `<? if(is_category($VolumeAndIssue)) { echo 'test'; } ?>`
 * returns nothing. So for some reason it considers the post not to be assigned 
   to this category. The plot thins.
 * Running get_the_category has gotten me really stumped. Consider this:
 *     ```
       <?php
       echo '<b>Categories: </b>';
       foreach((get_the_category()) as $category) {
           echo $category->cat_name . ' ';
       }
       echo '<BR /><B>VolumeAndIssue variable:</b> '.$VolumeAndIssue;
       ?>
       ```
   
 * [returns this](http://www.awayfromkeyboard.com/output.gif).
 * I then removed the ‘offline’ tag, just in case there was an issue with that being
   the first category. No change.
 * **Update 2:**
 * Something’s not right here.
 *     ```
       foreach((get_the_category()) as $category) {
           echo $category->cat_name . ' ';
       if(is_category($category->cat_name)) { echo '<br />debug:'.$category->cat_name.'<br />'; }	else { echo '<br />can\'t find category<br />'; }
       }
       ```
   
 * Unless I’m confused as to how this conditional works, it should always be able
   to find the category. However it returns false having not found the category 
   it just found. Huh?!?
 *  Thread Starter [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * (@hedgomatic)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/#post-1374358)
 * **Fixed:**
 * While I was indeed confused on what is_category() does, I did manage to figure
   out that the problem is a bug and/or limitation in WordPress: it doesn’t accept
   underscore (_) characters in category names.
 *  Thread Starter [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * (@hedgomatic)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/#post-1374408)
 * after looking at bug [11121](http://core.trac.wordpress.org/changeset/11121),
   I gathered that sanitize_title() in formating.php is responsible for cleaning
   the category names.
 * Nothing I saw there or in apply_filters() would create the issue however. I’ve
   no mind to edit the core of course, but it’d be nice to know if there’s a possible
   override for this.
 *  Thread Starter [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * (@hedgomatic)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/#post-1374419)
 * dashes didn’t seem to work either until I realized I shouldn’t use an alternate
   name for the slug.
 * Naming my slug “Volume1-Issue3”
 * and then doing:
 * query_posts(‘category_name=Volume1-Issue3’);
 * works.

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

The topic ‘query_posts not pulling 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/)
 * [the-loop](https://wordpress.org/support/topic-tag/the-loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 1 participant
 * Last reply from: [hedgomatic](https://wordpress.org/support/users/hedgomatic/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/query_posts-not-pulling-category_name/#post-1374419)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
