WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type where I have a taxonomy cities and a term berlin. Archive can be seen at example.com/cities/berlin and it's rendered normally from the archive.php template.

Now, I want to order them according to a custom field, start_date in this case, but still keep the original query around. So that when I navigate to example.com/cities/newyork the loop would still work as expected.

This is what I have but I only get the <p>Not Found</p> in the end.

Please help.

Thanks :)

global $query_string; //to keep the original query around
$args = array(
  'orderby'  => 'meta_value_num',
  'meta_key' => 'start_date',
  'order'    => 'DESC'
$posts = query_posts($query_string . $args);
if (have_posts()) : while (have_posts()) : the_post(); 

do stuff

<?php endwhile; else : ?>
    <p>Not Found</p>
<?php endif; ?>
share|improve this question
up vote 2 down vote accepted

You can't concatenate an array onto query_string like that. See Digging Into WordPress's post about looping for the right format. Alternately, you can use array_merge() like on the query_posts Codex page.

Consider using wp_reset_query() after your loop. Sometimes you'll also see people save the original $query_string to a new variable, modify $query_string, and then reset $query_string after the loop like so:

global $query_string;
$old_query = $query_string
// Modify your query, loop through it
$query_string = $old_query;
share|improve this answer
Thanks I'll try that :) – any_h Apr 17 '12 at 22:18
@any_h if this solved your problem, make sure to accept it as the answer. Otherwise, update your question and explain why this didn't work. – mrwweb May 8 '12 at 19:19

Old question, but it was on the front page, so it is my duty to post and say "Don't ever use query_posts()" To modify the query without destroying the original query, you should use the pre_get_posts hook.

function wpa_49346_pre_get_posts( $query ){
    if( is_tax() ){
        set_query_var( 'meta_key', 'start_date' );
        set_query_var( 'orderby', 'meta_value_num' );
        set_query_var( 'order', 'DESC' );
add_action( 'pre_get_posts', 'wpa_49346_pre_get_posts' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.