Title: multiple queries sorted by url string
Last modified: August 19, 2016

---

# multiple queries sorted by url string

 *  Resolved [jay.weeks](https://wordpress.org/support/users/jayweeks/)
 * (@jayweeks)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-queries-sorted-by-url-string/)
 * I need to have multiple loops run on the index page sorted by category, this 
   part is working. What isn’t working is the preservation of sorting posts by tags
   called in the url string. This is the function I’m using to query posts by category:
 *     ```
       <?php
       function query_single_category($kat) {
       	$category_id = get_cat_id($kat);
       	query_posts($query_string . "&cat=$category_id");
       	if ( have_posts() ) : while ( have_posts() ) : the_post();
       	include("post-content.php");
       	endwhile;
       	else :
       	endif;
       }
       ?>
       ```
   
 * This is how I’m calling specific categories in the template:
    `<?php query_single_category('
   residential') ?>`
 * Any ideas why this isn’t preserving the url string?
    I’m pretty sure my syntax
   is correct, I referenced the codex…would it have something to do with referencing
   the $query_string variable in functions.php?

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

 *  Thread Starter [jay.weeks](https://wordpress.org/support/users/jayweeks/)
 * (@jayweeks)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-queries-sorted-by-url-string/#post-1165110)
 * i just tested it, and inserting that code into the index template and $query_string
   worked.
    Now the issue is defining this variable for use in functions.php Any
   help?
 *  Thread Starter [jay.weeks](https://wordpress.org/support/users/jayweeks/)
 * (@jayweeks)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-queries-sorted-by-url-string/#post-1165132)
 * got it
 *     ```
       <?php
       function query_single_category($kat) {
       	$queryString = $_SERVER['QUERY_STRING'];
       	$category_id = get_cat_id($kat);
       	query_posts($queryString . "&cat=$category_id");
       	if ( have_posts() ) : while ( have_posts() ) : the_post();
       	include("post-content.php");
       	endwhile;
       	else :
       	endif;
       }
       ?>
       ```
   

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

The topic ‘multiple queries sorted by url string’ is closed to new replies.

## Tags

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

 * 2 replies
 * 1 participant
 * Last reply from: [jay.weeks](https://wordpress.org/support/users/jayweeks/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-queries-sorted-by-url-string/#post-1165132)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
