PHP Include And Variable Issue
-
I’m storing a value into a variable I’ve created called $mov_sub. I’m using the Exec-PHP plugin to put PHP into posts. This is the PHP I’ve got in my post:
<?php mov_sub = "123"; ?>
Then I’ve got a file included using PHP in my header.php file. The source code for the included file is along the lines of:
<?php if(is_single( array( 1079, 1088 ) ) ) if(isset($mov_sub)) { $sid = "&sid=$mov_sub"; } else { $sid = "&sid="; } echo "$sid"; } ?>
It’s only echoing &sid, not &sid=123 like it should be doing. I tested this outside of WordPress and it works fine. I thought maybe it wasn’t working because WordPress uses a function to create the post content called the_content() and I think functions only allow local variables unless you declare a global variable. So I edited the post-template.php file in wp-includes where the_content() function is located and added:
global $mov_sub;
but that didn’t work either. I’m really new to PHP and have been struggling with this for a few hours now. Does anyone know why it’s not working?
- The topic ‘PHP Include And Variable Issue’ is closed to new replies.