Here is the source of in_category
function:
function in_category( $category, $post = null ) {
if ( empty( $category ) )
return false;
return has_term( $category, 'category', $post );
}
You see, it’s actually has_term
. This is the same as has_category
function.
For tags, there’s no in_tag
function, but you can use has_tag
. It has the same functionality:
has_tag( $tag, $post );
Or you can use:
has_term( $tag, 'post_tag', $post );
where $post
can be omitted (default is current post).
They’re all the same!
Related Posts:
- how do I get the tag name from tag id?
- Do tags have dates?
- How can I let my audience tag my posts?
- Display tags in list without link
- How can you tie into the tag metabox?
- How to display the_tags() as plain text
- Display tags for current post in sidebar
- How important are WordPress tags for SEO purposes?
- Allow visitors to search by multiple tags (specific IDs)
- Massive Tags Remove Using MySQL
- Quicktags on all textarea.. Not working on plugin?
- how to change # of tag posts on /tag page?
- How can I remove certain HTML tags from the RSS feed?
- Stop WordPress removing tags when switching from HTML to Visual (TinyMCE)
- Link directly to the first post in an archive
- Set homepage to only display posts from one tag
- Individual css class for each tag in wp_tag_cloud
- Strict tag list – user should choose only existing tags for posts
- Special characters in tag get removed for comparison on save
- Display custom list of tags in post/page editor with hooks
- How to remove ‘noindex, follow, max-image-preview:large’ in search page WordPress 5.7 up
- Displaying Posts by tag dynamically in WordPress
- How to rename ‘TAG’ to ‘TOPIC’
- How to not show tags if the post doesn’t have any?
- Don’t show a tag on a post if it is the only post with that tag
- Remove the last character from tag name in tag archive page
- How to Override “Blog pages show at most” in tag.php [duplicate]
- Get current tag list in Gutenberg save function
- WordPress editor: “pick from existing tags” is gone?
- Return post tags with description
- How to display tag cloud without links
- Get tags for post_type
- Line of Tag information Is Formatted Strange
- How can I make an auto-fill search box auto-completing with the tags?
- How to get the Tags on Publish post hook?
- woocommerce product tags display
- Please help me to figure out how to display my tags
- Cross Site Related Posts?
- TinyMCE – how to select tags node from the place where the caret is?
- List tags by certain letter issue with special chars like å, ä and ö
- Change Post Class function
- Strip and tags from a specific div
- Mass remove a number of tags from a number of posts
- Require tags for bbPress topics [closed]
- How to enable all Tag Descriptions in loop?
- WordPress Tag Page Hook?
- Tags not working with custom post type
- How can i order get_the_tags?
- Add text to Title dynamically using tags
- videos not showing on my tag pages
- Checking if one of the post tags has options
- How to get all the available post tags using the WP Data Module?
- How to add a rest field to post tags?
- How to get links to previous and next archive page based on tag
- Code to check how many posts a tag has?
- How to add meta tags on password-protected homepage? [closed]
- How to make tag pages look as /tags/%tagname%/ in the URL?
- Remove ‘style=’ from Tag Cloud
- Order post by taxonomy
- Echo tags with an if statement and display php inside of the IF?
- Get Tag Slugs that start with a word
- Show all videos by tag name
- Print_r displaying two different post->ID if placed in sidebar or single.php
- Detect tag page and include an Image for that specific tag
- Buddypress – Adding Tags in Profile
- Do not run this code on posts with a specific tag!
- Automatically add tag (first 4 characters) to uploaded media
- How can I automatically hyperlink tag names that are in my post body to the tag page
- wp-cli error: “Term is missing a parent”
- Add a specific tag to default tag list
- Random tag in the post
- Remove little gray box from content page
- Get the publish date of the older post inside a tag
- How to test if the tag list is empty for the current page?
- Replace -tag in the_excerpt
- Get X post tags
- Can / should / how should I convert my WordPress categories to tags?
- Insert text BEFORE the “tag” title
- Title tag come up differently on search results
- Why doesn’t the_tags( ) accept empty string for first argument?
- tag based subscription
- Remove parentheses from tag cloud count
- the_tags outputs before echo
- Only display posts with a specific tag
- Prevent tag creation on the post edition page
- showing tag beside catagory
- Conditional tag for attachment posts
- Get multiple tags by slug
- How To get a list of popular tags by post views?
- Post order by selected tags
- WordPress editor, change code wrap (bbpress?)
- Get TOP x Tags from selected posts
- post specific tag cloud, how to display in descending order from popular to less?
- Tags as autocomplete values
- Need to return all tags – including empty ones – in list
- How do I exclude categories from get_tags?
- How can I add meta tags in the WordPress header?
- How to have H1 for site title only on Homepage?
- Custom message if tag returns empty results
- WordPress Title Tag Not Changing