0
votes

On a page of single custom type post, I'm trying to get current taxonomy term

$current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
print_r($current_term);

current_term, get_query_var('term') and get_query_var('taxonomy') return nothing

UPDATE:

$term = get_queried_object(); print_r($term) ; :

    WP_Post Object
(
    [ID] => 324
    [post_author] => 1
    [post_date] => 2019-10-17 14:18:37
    [post_date_gmt] => 2019-10-17 14:18:37
    [post_content] => The performance data 
    [post_title] => Diversified Fund
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => diversified-value-fund
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2019-10-31 20:44:43
    [post_modified_gmt] => 2019-10-31 20:44:43
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://hwcm.my/?post_type=funds&p=324
    [menu_order] => 1
    [post_type] => funds
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)
2

2 Answers

0
votes

You can use queried object

$term = get_queried_object();
print_r($term);
0
votes

have found the solution:

print_r(get_the_terms(get_the_ID(), 'fund_category'));

gives:

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 5
            [name] => US Equity
            [slug] => us-equity
            [term_group] => 0
            [term_taxonomy_id] => 5
            [taxonomy] => fund_category
            [description] => 
            [parent] => 0
            [count] => 6
            [filter] => raw
            [term_order] => 1
        )

)