• 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.

    $taxonomy=wp_list_categories('taxonomy=issue&echo=0&number=1&orderby=ID&order=DESC&show_count=0&style=none&title_li=');
    $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;

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘get_term_by and variables’ is closed to new replies.