WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#6590 closed enhancement (fixed)

Add has_tag function to determine if a post has a given tag

Reported by: Otto42 Owned by:
Milestone: 2.6 Priority: normal
Severity: normal Version:
Component: Template Keywords: has-patch 2nd-opinion has_tag tag
Focuses: Cc:

Description

As discussed on wp-hackers, this is a patch for a "has_tag" function. New Loop function which takes a tag slug, id, or name (or array of such) and returns true if the post has that tag, false if it doesn't. Also takes a null input and returns true if the post has any tag.

Useful for theme developers to produce different things depending on tags. Compare to "in_category", as this is basically the same thing but for tags.

Patch for trunk attached.

Attachments (2)

has-tag.diff (1.4 KB) - added by Otto42 6 years ago.
Add has_tag function.
has-tag.2.diff (1.2 KB) - added by Otto42 6 years ago.
Updated function to handle no tag case better

Download all attachments as: .zip

Change History (4)

Otto426 years ago

Add has_tag function.

comment:1 ozh6 years ago

  • Keywords has-patch 2nd-opinion has_tag tag added

Otto426 years ago

Updated function to handle no tag case better

comment:2 westi6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [8131]) Add new has_tag() template tag. Fixes #6590 props Otto42.

Note: See TracTickets for help on using tickets.