Show with echo if a post has two or more categories

To answer your question, if placed within the Loop – after, typically, while ( have_posts() ) : the_post(); in a single.php file – the code will work as follows:

  • The has_category( array( 'x', 'y' ) ) condition will be satisfied if the post is in either x or y, or both, regardless of whether it is in any other categories (assuming an otherwise unmodified main query and no other conditions).

  • In your example, if the post was in both “jeran” and “cow,” then
    $bplant would be echoed, but not $banimal. I think you probably
    already understand why.

  • If a post must have both of the two categories, then you’ll have
    to work the logic out accordingly- e.g., if ( has_category( 'x' ) && has_category( 'y' ) ), etc.

You might also conceivably run into problems with unique approaches to “single post pages.”