I need a way to see if a post has a particular tag.
The problem is that the ways I've found are dependent on being in the loop. This is in a plugin and occurs outside the loop.
I'd like to get the tags like I can get the title
To get the title I can:
$postStuff = get_post($post_ID);
$title = $postStuff->post_title;
But I can't seem to add something like:
$tags = $postStuff->post_tags;
I've tried the following with no luck:
has_tag('tagnamehere')
and
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
if ($this_tag->name == "tagnamehere" ) {
}
}
and even
$tags = wp_get_object_terms($post_ID, 'post_tag');
$tags_names= array();
foreach($tags AS $tag) {
if ($tag->name == 'tagnamehere') {
}
}
None of those work...
Any ideas?