{"id":35233,"date":"2004-02-16T22:43:19","date_gmt":"2004-02-16T22:43:19","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-variable-scope-headache\/"},"modified":"2016-08-18T18:17:08","modified_gmt":"2016-08-18T18:17:08","slug":"php-variable-scope-headache","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-variable-scope-headache\/","title":{"rendered":"PHP variable scope headache"},"content":{"rendered":"<p>ok, I thought it was a good idea but I&#8217;m starting to wonder&#8230;<br \/>\nI created 2 files, one news.php and one calendar.php with a short version of the regular index.php code plus a <code><br \/>\n&#036;cat = x;<\/code> on top of each file with the x replaced by the &#8220;news&#8221; and &#8220;calendar&#8221; category IDs respectively.  I get the desired effect when I access each file individually through my browser: one shows all the &#8220;news&#8221; and the other all the &#8220;calendar&#8221; events&#8230;<br \/>\nOnly problem is, what I wanted to do was to include both file in a <code>home.php<\/code> page with a <code>&lt;?php include 'directory\/news.php'; ?&gt;<\/code> type thing.<br \/>\nWhat happens is that the first <code>include<\/code> is just fine, but the second outputs the &#8220;Sorry, no posts matched your criteria.&#8221; part of the conditional statement.<br \/>\nI don&#8217;t know much about programming but I was guessing that maybe the <code>if (&#036;posts)<\/code> conditional always returns false because the variables have still values from the previous <code>include<\/code> so I tried resetting those variables but my syntax might be wrong or I&#8217;m just missing the point&#8230;  Not sure.<br \/>\nAny PHP guru in the house yo?! \ud83d\ude09<\/p>\n","protected":false},"template":"","class_list":["post-35233","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/35233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/35233\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=35233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}