Fetching wpdb data from a php file seems to break?

So I have an html element where the text reflects a text field in my database, this works normally. I need it to update every so often so I have:

<script>
setInterval(function(){
$(“#marque_element”).load(“XXXload_marque.php”);
}, 1000);
</script>

Which just grabs the echo from load_marque.php.

Inside of load_marque.php I simply have:

<?php
global $wpdb;

$Text = “Test Text”;
echo $Text;
?>

It works fine. And if I change the text in $Text then update, it also update in the html element.

But when I then try to pull from my database within load_marque.php it seems to break for some reason.

<?php

global $wpdb;
$marque_text = $wpdb->get_row ( “SELECT * FROM marque_text WHERE ID = ‘1’ “, OBJECT );
$Text = $marque_text->Text;
echo $Text;
?>

The html element text is blank.

I’ve been banging my head trying to figure this out. Can I NOT access my database using an outside php script?

Read more here:: Fetching wpdb data from a php file seems to break?

Leave a Reply

Your email address will not be published. Required fields are marked *