in_category() not working in WordPress 4.9.7

I have the following code in a template that used to work until I upgraded to WordPress 4.9.7

if (in_category( ‘vid’ )) { $vidliclass = ‘ class=”vid”‘;} else {$vidliclass = ”;}

Since the upgrade, posts that are in category vid don’t return true anymore.

I used the following code, to check on the category names of the posts:

$postcat = get_the_category( $post->ID );
if ( ! empty( $postcat ) ) {
echo esc_html( $postcat[0]->name );
}

And the posts that are in category “vid” are echoed as vid.

I also tried to replace “vid” with the category ID.

Can I replace in_category() with something else to check if the post is in category “vid”?

Read more here:: in_category() not working in WordPress 4.9.7

Leave a Reply

Your email address will not be published. Required fields are marked *