Passing WordPress variables to Ajax modules (2 posts)

  1. Blutarsky
    Posted 5 years ago #

    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:

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

    What do you think? Does someone see any drawback?

  2. Blutarsky
    Posted 5 years ago #

    Too difficult?

Topic Closed

This topic has been closed to new replies.

About this Topic