Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having trouble running query_posts when my page loads for the first time, i.e Session is empty.

When the page loads for the first time and the SESSION is empty, the following code runs:

    <?php
    $id = 106;
  if ((empty($_SESSION['r1']))){            
            echo "This Line Prints";
            query_posts("cat=-.'$id'&".$query_string);
            wp_reset_query();
                echo "This Line also Prints";
        }
    ?>

The two statements mentioned in the above code are printing but the query_posts is not running here. However when I am running it outside the session it is working fine :S How can I run this query_posts if the Session is empty? Why doesn't this code work?

share|improve this question
1  
You're calling wp_reset_query() right after you run query_posts(); so how do you know that query_posts() isn't running, and simply being reset? –  Chip Bennett Feb 8 '12 at 17:29
    
I've already checked that without calling wp_reset_query() & it doesn't work either –  Sufiyan Ghori Feb 8 '12 at 17:35
    
where are you setting $id? also- remove the dot and single quotes around $id. –  Milo Feb 8 '12 at 17:55
    
this is not the issue either, as if i replace $id with the constant category ID it doesn't work either , btw $id is declared right above this code –  Sufiyan Ghori Feb 8 '12 at 17:59
    
We need to see actual code that you're using, not test code. –  Chip Bennett Feb 8 '12 at 18:05
show 1 more comment

1 Answer

up vote 2 down vote accepted
if ( empty($_SESSION['r1']) ) {
    global $query_string;         
    query_posts($query_string . "&cat=-" . $id);
}

This should work, depending on $id is set.

share|improve this answer
add comment

Your Answer

 
discard

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.