Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

wpnewbie69 on "Change this "if parent category is..." function to accept post slugs?"

$
0
0

This code is from the codex.

/* ==  If In Parent Category... ==============================*/

	if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
		function post_is_in_descendant_category( $cats, $_post = null ) {
			foreach ( (array) $cats as $cat ) {
				// get_term_children() accepts integer ID only
				$descendants = get_term_children( (int) $cat, 'category' );
				if ( $descendants && in_category( $descendants, $_post ) )
					return true;
			}
			return false;
		}
	}

I use it in the theme like this:

if ( post_is_in_descendant_category( 11 ) ) ...

It only accepts the post ID (11), however, and I'd like it to accept the slug. Is there a way to alter this code somehow to accept the slug?


Viewing all articles
Browse latest Browse all 8245

Trending Articles