[closed] get_term_by and variables (2 posts)

  1. Anna
    Posted 3 years ago #

    Is there any reason why the following code would not work?

    My situation: I have a custom category set up called 'Issue'. What I want to do is get the most newly created category (which is 'Volume 2 Issue 1') and get its ID.

    I have a very hacky solution at the moment, but if anyone can figure out why the last 3 lines don't work, it would be fantastic.

    Alternative and cleaner solutions would also be appreciated.

    $tax = strip_tags($taxonomy);
    $newtax = "'".trim($tax)."'";
    $getID = get_term_by('name', $newtax, 'issue');
    $curID = $getID->term_id;

    Doing a var_dump on $getID only results in this bool(false)

    The interesting thing is that this code works (but I cannot use it because it would require manually changing the code each time I create a new category).

    $getID = get_term_by('name', 'Volume 2 Issue 1', 'issue');
    $curID = $getID->term_id;
  2. Anna
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.