PODSCMS + jQuery

I am changing the subject and pulling data from my PODS tables. I also have a custom DBTOXML.php file that is called from index.php using an AJAX call. Since this is a special file that I introduced into the Wordpress theme, it does not seem to be able to find my Pod class, and therefore I cannot extract data from my PODS tables. Any idea how I can get this DBTOXML.php to work with PODS?

Here is the complete code for DBTOXML.php

<?php
$rwhdata = new Pod('rainwater');
$p = $rwhdata->fetchRecords();
$dom = new DOMDocument("1.0");
$node = $dom->createElement("Markers");
$parnode = $dom->appendChild($node);
while ($p->fetchRecord()) {
    $node = $dom->createElement("marker");  
    $newnode = $parnode->appendChild($node); 
    $locString = $p->get_field('location');
    list($latitude,$longitude)=split(',',$locString);
    $newNode->setAttribute("latLocation",$latitude);
    $newNode->setAttribute("longitude",$longitude);

}
echo $dom->saveXML();
?>

and this is a jquery call ...

$.ajax({
                url:'<?php echo bloginfo('template_url').'/DBTOXML.php';?>',
                type:'POST',
                data:"",
                success:function(results)
                {
                    //Some work here

                }
                });
+3
source share
2 answers

That's right, you'll want to use the following code to include WP in the page so that you can use any of the php functions contained in activated plugins (in this case, Pods):

require_once(realpath('../../../wp-load.php'));
+2

, , DBTOXML.php, , PODS. , , ...

0

Source: https://habr.com/ru/post/1749541/


All Articles