I have a page template that is including another file via
require_once. I want this included file to have access to the
$post object but it can't find it.
So I ran something like this to see what's happening
<?php $post_title = $post->post_title; echo "Post:<br/>"; var_dump($post_title); require_once('inc/external.php'); ?>
<?php global $post_title; echo "External post:<br/>"; var_dump($post_title, true); echo "<br/><br/>"; ?>
Not only does
external.php not see $post_title, but it prints out of order:
External post: NULL Post: Title of the Post
Why would the echo/var_dump in the included file run before the original? I feel like this is linked to the fact that the variable can't be read in the included file.