How to pull a list of posts in a category while exluding posts in subcategories of the category

If you use category__in and category__not_in instead, it will only pull the posts that are in that category, not the subcategories as well. For your code, this would look something like this: $args = array( ‘category__in’ => $cat, ‘category__not_in’ => $catHidden ); Note: this will only exclude posts that are directly in the category as … Read more

category__not_in and id values from variable

get_category_by_slug() returns a category object or FALSE: $cat1 = get_category_by_slug( ‘cata’ ); print ‘<pre>’ . htmlspecialchars( print_r( $cat1, TRUE ) ) . ‘</pre>’; Result: stdClass Object ( [term_id] => 3 [name] => Cat A [slug] => cata [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => category category__not_in and id values from variable => [parent] => … Read more

Get Categories Where Taxonomy Equals ‘n’

get_categories() only lists categories, so you shouldn’t be seeing any terms from the custom taxonomy. What you want to use is get_terms() which takes a taxonomy as an argument. As you can read about in this answer, get_terms() is actually used by get_categories(), it just prefills the “taxonomy” argument with “category.” If you swap in … Read more

Different Category Headers using in_category and elseif

The unnecessary semi-colon is probably causing the error. <?php } else { ;?> should be <?php } else { ?>. Try this: <?php if (in_category( array(6,14,15,13) )) { ?> <div id=”eatheader”> <?php } elseif (in_category( array(7,11,12,10,9) )) { ?> <div id=”goheader”> <?php } elseif (in_category( array(4,16,17,18,19) )) { ?> <div id=”playheader”> <?php } elseif (in_category( … Read more