AJAX and accessing the WP database. (1 post)

  1. mitel
    Posted 5 years ago #

    I am using a custom template that after the 'the_excerpt()' call I am 'including' another php file. The php file has 2 div tags side by side, the left div has a map image and the right div tag is empty. In the map are HTML hotspots that when moused over call a jQuery request to load another php file, getBranch.php. This second php file has various WP-Query statements and the one that is run will depend on the 'location' value sent from the map hotspot, I.E.

    jQuery("#North").mouseover(function () {
    jQuery('#location').load('http://mysite/wp-content/themes/mytheme/getBranch.php?location=north', function() {
    /*alert('Load was performed.');*/

    The jQuery function is working fine, however, the getBranch.php file has no access to WP_Query so I am unable to run any SQL queries, I simply get "Fatal error: Class 'WP_Query' not found".
    I have read many, many articles on this problem and can see the solution, add_action etc, but cannot put this all together.
    I have tried the 'sloppy' way of solving this by including the WP core files, wp-config, wp-load and wp-includes/wp-db but I just get a handful of PHP errors. I am using PHP 5.3.
    Can somebody create a 'step by step' example of how to do this properly including which code goes into which files please?

Topic Closed

This topic has been closed to new replies.

About this Topic