Note that there are some explanatory texts on larger screens.

plurals
  1. POLosing reference to $_post variable?
    primarykey
    data
    text
    <p>In the code below, the echo at the top returns true, but the echo at the bottom returns nothing. Apparently the code in between is causing me to lose a reference to the $_post variable?</p> <pre><code>&lt;?php echo "in category: ".in_category('is-sidebar'); //RETURNS TRUE if (!get_option('my_hide_recent')) { $cat=get_cat_ID('top-menu'); $catHidden=get_cat_ID('hidden'); $myquery = new WP_Query(); $myquery-&gt;query(array( 'cat' =&gt; "-$cat,-$catHidden", 'post_not_in' =&gt; get_option('sticky_posts') )); $myrecentpostscount = $myquery-&gt;found_posts; if ($myrecentpostscount &gt; 0) { ?&gt; &lt;div class="menu"&gt;&lt;h4&gt;&lt;?php if ($my_sidebar_heading_recent !=="") { echo $my_sidebar_heading_recent; } else { echo "Recent Posts";} ?&gt;&lt;/h4&gt;&lt;ul&gt; &lt;?php global $post; $current_page_recent = get_post( $current_page ); $myrecentposts = get_posts(array('post_not_in' =&gt; get_option('sticky_posts'), 'cat' =&gt; "-$cat,-$catHidden",'showposts' =&gt; $my_recent_count)); foreach($myrecentposts as $idxrecent=&gt;$post) { if($post-&gt;ID == $current_page_recent-&gt;ID) { $home_menu_recent = ' class="current_page_item'; } else { $home_menu_recent = ' class="page_item'; } $myclassrecent = ($idxrecent == count($myrecentposts) - 1 ? $home_menu_recent.' last"' : $home_menu_recent.'"'); ?&gt; &lt;li&lt;?php echo $myclassrecent ?&gt;&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php } ; if (($myrecentpostscount &gt; $my_recent_count) &amp;&amp; $my_recent_count &gt; -1){ ?&gt;&lt;li&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;/site-map"&gt;View all&lt;/a&gt;&lt;/li&gt;&lt;?php } ?&gt;&lt;/ul&gt;&lt;/div&gt; &lt;?php } } global $sitemap; echo "in category: ".in_category('is-sidebar'); //RETURNS NOTHING </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload