{"id":1362385,"date":"2010-01-28T01:12:53","date_gmt":"2010-01-28T01:12:53","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/problem-with-wpdb\/"},"modified":"2016-08-19T15:43:01","modified_gmt":"2016-08-19T15:43:01","slug":"problem-with-wpdb","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/problem-with-wpdb\/","title":{"rendered":"problem with $wpdb"},"content":{"rendered":"<p>Hi, I&#8217;m using $wpdb in my theme files, (a custom Thematic child theme), and everything is working fine, BUT if i modify a template file (header-extensions.php) located in the PARENT theme directory, i can&#8217;t seem to connect to the database.<\/p>\n<p>code that works fine in a php file located in my CHILD theme folder works, such as<\/p>\n<pre><code>global $wpdb;\n$lightboxes = $wpdb-&gt;get_results( &quot;SELECT * FROM wp_usermeta WHERE meta_key = &#039;lightbox&#039; AND user_id = $user_ID&quot;);\n&lt;select&gt;\n&lt;option&gt;--Select from your lightboxes--&lt;\/option&gt;\n    &lt;?php\n\n\tforeach ($lightboxes as $lightbox) {\n\t\tif ($lightbox-&gt;meta_value != $editLB) {\n\t\t\techo &#039;&lt;option&gt;&#039;.$lightbox-&gt;meta_value.&#039;&lt;\/option&gt;&#039;;\n\t\t}\n\t}\n\n\t?&gt;&lt;\/select&gt;<\/code><\/pre>\n<p>but, the following code, while it seems to connect to the database, returns no results<\/p>\n<pre><code>&lt;?php\n\t\t\t\t\t\tglobal $wpdb;\n\n\t\t\t\t\t\tif ($user_ID) {\n\t\t\t\t\t\t\t$getLightboxes = $wpdb-&gt;get_results( &quot;SELECT * FROM wp_usermeta WHERE meta_key = &#039;lightbox&#039; AND user_id = $user_ID&quot;);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!$getLightboxes) {\n\t\t\t\t\t\t\techo &#039;&lt;li&gt;&lt;a href=&quot;http:\/\/therapytest.com\/wordpress\/?page_id=40&quot;&gt;You have no lightboxes&lt;\/a&gt;&lt;\/li&gt;&#039;;\n\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tforeach ($getLightboxes as $lightbox) {\n\t\t\t\t\t\t\t\techo &#039;&lt;li&gt;&lt;a href=&quot;&quot;&gt;&#039;.$lightbox-&gt;meta_value.&#039;&lt;\/a&gt;\n\t\t\t\t\t\t\t\t&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;&quot;&gt;view&lt;\/a&gt;&lt;\/li&gt;&lt;\/ul&gt;\n\t\t\t\t\t\t\t\t&lt;\/li&gt;&#039;;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t ?&gt;<\/code><\/pre>\n<p>is there any reason why i am unable to connect to the database and\/or return results from the files located in a PARENT theme folder?<\/p>\n","protected":false},"template":"","class_list":["post-1362385","topic","type-topic","status-closed","hentry","topic-tag-child-them","topic-tag-database","topic-tag-no-results","topic-tag-parent-theme","topic-tag-thematic","topic-tag-wpdb"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1362385","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\/1362385\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=1362385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}