Category Name from Default_Category?

This topic contains 7 replies, has 2 voices, and was last updated by  Stiofan O’Connor 6 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #418861

    jahusdtc
    Expired Member
    Post count: 162

    Have a feeling this is a very elementary question…but how do I get the Category NAME from the $post->default_category?

    I have tried several things, but have a mental block for some reason.

    Thought might be:
    get_term_by(‘id’, $post->$default_category, ‘gd_placecategory’);

    ???

    But no joy :{

    Can you suggest?

    #418864

    jahusdtc
    Expired Member
    Post count: 162

    Still looking, but SHOULD have put in…

    get_term_by(‘id’, $post->default_category, ‘gd_placecategory’);

    Had extra $ in earlier message! Whoops!

    #418957

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    is this solved then?

    Stiofan

    #418965

    jahusdtc
    Expired Member
    Post count: 162

    Didn’t show a category for me. I just wrote that “Whoops” message because I had improperly written what I tried….that didn’t appear to work.

    What would you say would get the default category’s name?

    Could you let me know that one snippet, please?

    Trying within add_action(‘geodir_wrapper_open’, …)

    #418966

    jahusdtc
    Expired Member
    Post count: 162

    Addendum to above…am trying on my localhost.

    #419053

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    The function you use should get it, this is how i woudl do it:

    
    
    global $post;
    //echo "the default cat id is:".$post->default_category; // uncomment for testing.
    $term = get_term_by('id', $post->default_category, $post->post_type.'category');
    //print_r($term); // uncomment for testing.
    echo $term->name;

    Stiofan

    #419084

    jahusdtc
    Expired Member
    Post count: 162

    Thank you, thank you, thank you!
    Not sure why I was struggling so much with this, but this was wonderful and clear.

    My computer is happy again :}

    Appreciate your taking the time….whew!

    #419100

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    You are welcome! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount