WordPress.org

Support

Support » How-To and Troubleshooting » Passing WordPress variables to Ajax modules

Passing WordPress variables to Ajax modules

  • Hi there, I’m using jQuery to enlighten web page load.

    Basically php modules are launched on request by jQuery and main page content is updated on the fly. Works fine.

    The main problems are:
    – WordPress needs to be re-initialized by Ajax pages;
    – Re-initialization resets all wordpress variables

    I’m using the following technique to bypass this problem:
    – use wp-load to expose Worpdress to ajax loaded module;
    – restore global vars using session variables;

    Fore example, in single.php

    .
    .
    $_SESSION['post'] = $post; // save post data
    .

    in Ajax loaded external php module:

    <?php
        require_once($_SERVER["DOCUMENT_ROOT"]. '/wp-load.php' );
        global $post;
        $post; = $_SESSION['post'];
    .
    .

    What do you think? Does someone see any drawback?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Passing WordPress variables to Ajax modules’ is closed to new replies.