• Resolved David Gard

    (@duck_boy)


    Hey all,

    I am pulling the name of the selected Tag or Category out of my query string using $_GET[‘tag’]/$_GET[‘cat’]. I’m wondering if there is anyway of getting the Tag/Category name from just the slug, so that I can output it on the page?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • See Function_Reference/get_term_by

    $cat_slug = 'my-slug'
    get_term_by('slug',$cat_slug,'category');

    Thread Starter David Gard

    (@duck_boy)

    Hi Michael,

    May be a stupid question, but how do you out put that data? When I try to assign get_term_by(‘slug’,$cat_slug,’category’); to a variable or echo it, as below, I get ‘Catachable fatal error: Object of class stdClass could not be converted to string’

    $term = get_term_by('slug',$cat_slug,'category');
    echo get_term_by('slug',$cat_slug,'category');

    When just leaving as you put above nothing is output on the screen.

    Thanks.

    Thread Starter David Gard

    (@duck_boy)

    Ok, putting it in an Array will capture the data, but I still cannot output it.

    $term = array(get_term_by('id',$slug_ID,'category'));
    print_r($term); // Works, but don't need all the data.
    print_r($term->name); // Does not disply anything. Name is listed in the above output.
    echo $term->name // Also does not work

    Any help appriciated.

    Thanks.

    Thread Starter David Gard

    (@duck_boy)

    Got help from a friend, sorted.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get Tag/Category name from the slug’ is closed to new replies.