post tags in plugin (not in loop) (2 posts)

  1. DougYITBOS
    Posted 7 years ago #

    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:



    $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?

  2. Alex Angas
    Posted 7 years ago #

    Did you ever find an answer to this? I'm having the same problem.

Topic Closed

This topic has been closed to new replies.

About this Topic