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 am developing a Wordpress theme that uses a lot of AJAX. It is composed of two main pages: the index, which displays a list of posts, and a viewer (similar to single.php).

When a post is clicked in index.php, Wordpress takes the user to viewer.php, which displays the post.

In viewer.php the selected post is displayed, and the links prev an next will load the previous or next posts with AJAX, instead of the current one.

My problem is that in index.php, different category filters can be applied, so I would want the exact sequence of posts displayed in index.php passed to viewer.php, so the next and post will use the sequence of posts that was displayed in the homepage.

I've been reading the docs to understand how WP handles the $wp_query info, but I am not sure I understand it, so I would appreciate your help.

share|improve this question

In your index.php

global $query_string;
setcookie('my_wp_query', $query_string);


global $query_string;
$_SESSION['my_wp_query'] = $query_string;

whatever you prefer.

share|improve this answer
Sorry Dick but I am not sure I understood. Could you explain what $query_string contains? If I understood correctly, if index.php doesnt have any filters applied $query_string will be empty. Plus every filter refresh is done via AJAX, so I am not sure $query_string would work – 0al0 Aug 3 '11 at 13:06
$query_string holds the current loop query. – Tim Bezhashvyly Aug 3 '11 at 13:08
In my index.php, without any filters aplied, its empty – 0al0 Aug 3 '11 at 13:16
It has to be. Try querying posts for a category or any other criteria and you will see the difference. – Tim Bezhashvyly Aug 3 '11 at 13:29

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.