Posted on Nov 25, 2009

WordPress Blown: declare global $post; or you’re effed

Was tweaking a query to pull current post category and the darn thing wasn’t working right until i declared global $post; .  Just thought I’d warn the masses.  Here’s the snippet:

<?php
 global $post; //important!!
 foreach(get_the_category() as $category) {
 $cat = $category->cat_ID; }
query_posts('cat=' . $cat . '&order=DESC&showposts=-1'); ?>
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>