in_category

Definition:
function in_category( $category, $post = null ) {}

Check if the current post in within any of the given categories.
The given categories are checked against the post’s categories’ term_ids, names and slugs. Categories given as integers will only be checked against the post’s categories’ term_ids.

Parameters

  • int|string|array $category: Category ID, name or slug, or array of said.
  • int|object $_post: Optional. Post to check instead of the current post. (since 2.7.0)
  • $post

Return values

returns:True if the current post is in any of the given categories.

Source code

function in_category( $category, $post = null ) {

	if ( empty( $category ) )

		return false;



	return has_term( $category, 'category', $post );

}

2071

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: