You should wrap your condition with brackets according to PHP syntax:
if (has_tag('Cat', $post_id)) {
$taganimal = "Cat";
}
If you need to check multiple tags you can use something like
foreach (['Cat', 'Dog'] as $animal) if (has_tag($animal, $post_id)) {
$taganimal = $animal;
break;
}
but it would find only the first tag listed in array in case the post has several of them.
Related Posts:
- Tags to Post-ID mysql query. Tag Search
- show only one category and filter by tag
- Find post tags words in post content and link them to tag URLs
- Related posts by searching post tags of single post as terms
- Including categories in search results
- WordPress removing tags?
- Add tag to post api wordpress
- Set tags for a post – without tag creation
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- How to remove Nextpage tag inside posts text depending of utm_campaign
- Verify if tag is used on posts
- Display all search results
- Plain-text tag list?
- Display posts by tag on page
- Edit a post from frontend. post_tags get saved, but not separated
- Convert IPTC keywords to blog post tags
- Search posts by post author name
- Search not working with title and content
- how to limit and display tag?
- how to hide specific post from google search
- Include related posts on a page
- How to search only by post title and category?
- Search widget breaks when using multiple loops?
- How to display post tags
- How to add shortcode tags in single.php [closed]
- Remove post_tag from default post type, add custom taxonomy
- Pagination not working on custom query
- What Defines What Category A Post Picks (if in multiple)
- How can I get all posts data from within a paginated search result?
- Search query – exact post title match
- Does an action fire when adding a tag via the “Tags” meta box?
- pagination hook doesn’t work with search results
- how to programmatically change post tags
- Filter Posts By Tag
- Search for posts based on their url in the admin?
- WordPress post tag & custom field
- wp_query ‘s’ parameter does not work with custom post type
- WP Query related posts by current page Tag ID
- How to display all posts assigned to some tag?
- How To Add One Tag to Multiple Posts?
- Add Post Tags to Body Class
- Differentiate between posts and pages in search results
- How to prevent WordPress from updating the modified time?
- Count search results in heading
- Private Posts/Pages & Search
- WP Query – duplicated posts once including tags in search results
- Display number of posts via adress bar?
- wp_tag_cloud() and the_taxonomies() work but not the_tag()
- How to add Tags Filter in wordpress admin dashboard
- Prepend or add an Image to the content of a Post
- Display post from current category and same tag?
- How to change wordpress dates to native language (even if the languge not available i wordpress)
- Should I use posts or pages in this scenario?
- Display posts with tag that matches current post title
- How can I make a post that belongs to a category or have specific tags, display different from the other single posts?
- Using permalinks, category slugs, and tag slugs
- “more” tag doesn’t appear when browsing category achives or search
- Print all the tags from a custom post type Please
- Display tag image in post using Taxonomy Images plugin index.php
- Add multiple tags to multiple posts
- Help with Taxonomies
- How to filter my search in post if contains a word in title, content or excerpt?
- Search results posts_orderby and ID
- Posts and Attachments with “Published” status in Search
- WP_Query: Mixing category__in and tag__in together
- How to add tags (custom taxonomy) to post class css?
- How can I hide tags on a child-category page, if that tag has not been used?
- How do I change the core post search algorithm? Where is it found/constructed?
- How to get Tags with specific post id
- How to get a post’s content? [closed]
- How Do I Get My Post Tags to Alphabetize?
- WordPress query_posts by tag doesn’t work anymore(?)
- Conditionals if tags exist?
- Displaying posts that belong to a specific author
- How to add add more properties to WP_Post object in search results loop
- Display related post by tag name of current post
- How to remove specific tag from multiple posts?
- Total number of posts in query (category/tag/author/search results/main page…)
- Extracting relevant tags associated with that particular single post only
- How to change the layout of posts when viewing all posts by tag [closed]
- Count several post tags
- How to get post with associated categories and tags names instead of ids with rest api?
- Does WP automatically tag posts into the archive?
- Tags on products vs tags on blog posts. An easy way to duplicate them
- Changing Post Tag Color Based On Post Count
- Removing all post tags except a given list
- Having pages after specifying post_type post
- How to check if there are posts with the same tag
- In what context should Categories and Tags be used
- How to compare post tags?
- Would a “hub” page work better as a page or a post?
- Add post tags to previously created custom post type
- Why does WordPress search returns same number of results for every search query?
- Hide parts of the post content after typing it’s name or searching it by category
- search content of pages and list in wp-admin
- How to exclude the word “class” from being matched in search?
- Plotting posts on a graph
- Short link to read complete post
- Delete all Tag Links from Posts
- How to add tag(s) to all posts from a specific category? [duplicate]