{"id":1363143,"date":"2010-01-28T19:57:54","date_gmt":"2010-01-28T19:57:54","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/odd-custom-field-behaviour-in-sidebar\/"},"modified":"2016-08-19T15:43:26","modified_gmt":"2016-08-19T15:43:26","slug":"odd-custom-field-behaviour-in-sidebar","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/odd-custom-field-behaviour-in-sidebar\/","title":{"rendered":"Odd custom field behaviour in sidebar"},"content":{"rendered":"<p>Hi folks,<\/p>\n<p>I&#8217;ve got a custom field called is_homepage which I define in the templates using <code>$is_homepage = get_post_meta($post-&gt;ID, &#039;is_homepage&#039;, true);<\/code><\/p>\n<p>Within the sidebar I have this code:<\/p>\n<pre><code>if (is_page()) {\n\tif ($is_homepage == TRUE) {\n\t\tif (!function_exists(&#039;dynamic_sidebar&#039;) || !dynamic_sidebar(&#039;Homepage Top&#039;)) : endif;\n\t\tif (!function_exists(&#039;dynamic_sidebar&#039;) || !dynamic_sidebar(&#039;Homepage Bottom&#039;)) : endif;\n\t} else {\n\t\tif (!function_exists(&#039;dynamic_sidebar&#039;) || !dynamic_sidebar(&#039;Pages Top&#039;)) : endif;\n\t\tif (!function_exists(&#039;dynamic_sidebar&#039;) || !dynamic_sidebar(&#039;Pages Bottom&#039;)) : endif;\n\t}\n}<\/code><\/pre>\n<p>So as you can see I have 2 widgetised sidebars for both regular pages and the homepage itself. The reason there are 2 for each one is just in case I want to add something to the middle of a sidebar and there isn&#8217;t actually a widget for it, I can just code it inbetween.<\/p>\n<p>Now here&#8217;s the weird thing. Even with the custom field defined as TRUE on the actual homepage (reading settings dictate that the home page is a static page, not the blog), this code doesn&#8217;t recognise the variable. Or to be more precise, the entire sidebar template file doesn&#8217;t recognise it, even though I&#8217;ve defined it at the top.<\/p>\n<p>Whenever a page is loaded it shows the standard page sidebars, regardless of the custom field having a value. If I change the code to say <code>if ($is_homepage == FALSE) {<\/code> it loads the homepage sidebars on all of the standard pages (including home).<\/p>\n<p>Can anyone see where I&#8217;m going wrong?<\/p>\n<p>Cheers,<br \/>\nRobert<\/p>\n","protected":false},"template":"","class_list":["post-1363143","topic","type-topic","status-closed","hentry","topic-tag-custom-fields","topic-tag-sidebar"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1363143","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\/1363143\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=1363143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}