I have been struggling with this for a while now.
What I found is this:
<div id="include"></div>
<script>
$(function(){
$("#include").load("/test.php");
});
</script>
This does work when in test.php is a simple code like:
<?php echo 'echo world'; ?>
But it doesn't work when I want to grab Wordpress variables.
<?php $current_user_id = $current_user->ID;
echo $current_user_id; ?>
There's nothing outputed. No error. Just a blank.
It's like it doesn't send the variables to the test.php. So test.php doesn't echo values filled. When I use <?php include 'test.php';?> it does fill the variables and works as I wanted.
So basically, .load simply loads the file.
But I want <?php include;?> to be executed instead of .load.
When I use <?php include;?> I can grab variables, which I need.
Is there other command instead of .load to do that?
Any help would be appreciated.
$current_userthat boots WordPress, since calling a PHP manually won’t boot it for you?<?php include 'test.php';?>it does fill the variables and works as I wanted.