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.

My home.php shows a list of (N) posts and << Previous & Next >> links. When clicked, I want to fetch previous/next list of (N) posts using Ajax. This is: I do NOT want to load the entire page. I just want to get the posts' list and append it to current.

For this I make an ajax request and send href (URL) as parameter. The problem is I do not know how WordPress converts a URL to global $query_string. I want to reuse WordPress' tested code instead of writing my own. Please help

For example: I want to fill $query_string for this URL: http://example.com/page/2/?location=boston

share|improve this question
    
I think one of these plugins might do what you want: wordpress.org/extend/plugins/monkeyman-rewrite-analyzer askapache.com/htaccess/rewriterule-viewer-plugin.html –  AutoBlogged Jan 13 '12 at 22:38

2 Answers 2

Check out WP::parse_request() - unfortunately, it was never really designed for public use. You could try this, not sure of the repercussions:

global $wp,
       $wp_the_query;

// Grab the request_uri component of the referer URL.
if ( ! $url = parse_url( $_GET['my_referer_parameter'] ) )
    return 'Oh dear, poorly formed referer.';

// Ewww! Trick WP::parse_request by spoofing REQUEST_URI. 
$_SERVER['REQUEST_URI'] = $url['path'] . "?{$url['query']}";

$wp->parse_request();
$wp->query_posts();

// $wp_the_query should now be populated with posts queried by your referer.
while ( $wp_the_query->have_posts() ) {

    $wp_the_query->the_post();
    the_title();

}
share|improve this answer

While the question of processing links is interesting on its own, I think for the Ajax use case it would be more simple and reliable to output more specific information in page body as JS variable that Ajax would submit.

Common current practice for such is to use wp_localize_script() to pass data.

share|improve this answer

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.