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.”
Related Posts:
- How to display related posts from same category?
- How to show related posts by category
- How to add category to: ‘wp-admin/post-new.php’?
- Setting Custom Sort Order of Posts within a Category
- Display all posts from specific categories on a page
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- How to disable Uncategorized category URL?
- Add role that restricts user to post in specific category
- Count posts in category including child categories
- Add default content to post (for specific category)
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Display most recent post in category instead of archive?
- Archived Posts in Wrong Category
- get_post_type_archive_link(‘post’) returns current category archive
- Display all posts under child sub category in sidebar on post page?
- How do I get the slug of a custom taxonomy category of a post?
- Featured Posts for Category Pages
- Authors in menu, template list post by author
- Get user’s most published categories
- Conditional that checks if a current category has any subcategory with posts
- How to set post expiration date and time and move the page to archive after expiration [closed]
- Count to how many categories a post belongs to
- How can I remove posts of a certain category from homepage after a specified time period?
- How To Remove Certain category Posts From the Blog Page
- Add icon/badge next to posttitle of specific category
- Edit custom post type admin menu link
- How to display WordPress archive into three columns [closed]
- Get current category id from post page wordpress
- Get mixed category random posts
- Using wp_list_categories like the the_category (showing just current categories of a post)
- Saving category to a post, before publishing the post
- Should I use posts or pages in this scenario?
- Stop users posting into category while still seeing contents of the category
- How to allow users to post only in certain category and hide elements from edit page?
- Need help with category listing!
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- How to make the first post in the loop be styled like a “new / featured” post?
- How to display two random-post sections that are each under their own category
- How can you display all sibling categories to a post?
- How to create a sub post?
- Category page when using static front page
- How to create a “latest news” page showing a list of posts from blog category
- how to hide empty fields of post category description?
- how can i display my posts alphabetically?
- Change Post Title For Specific Category
- How to have more than one page for your posts if you have 8 posts but can store max 4 on a page
- Extract wordpress posts content and category content
- All categories displays the same posts
- Having pages after specifying post_type post
- Get latest post from categories
- How to create a playlist for audio associated with posts per category
- How to show a featured image inside a post in only 1 single category
- Display Parent Category of a Post belonging only to Subcategory
- Highlighting Current Category in the Archive and Feeds page
- Get current taxonomy and display query accordingly
- Can I style single post that are in multiple catergories?
- Geting error in post and category [closed]
- Display most recent posts in category with Twenty Ten theme widget
- Display a specific category in a focused area of my site
- How to make ajax load posts from the current category?
- Show single post child category from a determined parent
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- how to filter posts by category without page load (ajax) in wordpress?
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Create/Set Category as Title of Post
- How to distinguish pages created by woocommerce?
- How to display related post from same category in single.php
- Save All Post Permalink From A Specific Category into a .txt file
- show image gallery in archives or category page
- Page with Category Returning 1
- get current index of post content in category page
- Get 5 most recent categories
- Dynamically load posts based on category
- Get Categories & Posts With Type Article
- Nothing appears using get_the_excerpt() in category.php
- Set multi posts random categories and tags
- Add new post only in assigned category
- Changing the Category for all posts of an Author
- Custom plugin to get related posts by category
- Unable to uncheck a category in a post
- Admin Post List Only Show One Category
- Add category attribute to custom recent post shortcode
- Same sidebar in all posts as in the category
- How do I list categories and the common categories for posts beneath those categories?
- Latest Posts not in the right order
- Retrieve latest post by multiple categories with ID
- How to set a link to custom archieve page
- How to Include a common category in a custom Category Search
- How to display only one post on first category page and rest on next pages?
- each user having category with their name and can add sub categories post in that category
- Can’t assign another category other than Uncategorized int he following front end post submission form?
- Viewing category won’t show up Custom post type posts
- exclude certain categories from posts
- How to display my categories in a list (to a post, not the sidebar)?
- wordpress category Description not allowed tag
- Sort Posts Alphabetically Based on Specific Category (Divi)
- I have a website issue I am trying to resolve
- How to sort posts alphabetically based on a specific parent category