Search code examples
wordpressfunctiontaxonomy

Get the terms from a custom taxonomy without posts


What I am asking is, is there a built-in function that gets the the result of the following mysql query? get_terms() seems to get only the terms that are assigned e.g. to a post and not the whole list.

select 
    name
from
    wordpress.wp_terms
where
    term_id in (select 
            term_id
        FROM
            wordpress.wp_term_taxonomy
        where
            taxonomy = 'custome_taxonomy')

Solution

  • I think you have a misunderstanding about get_terms and don't know the purpose of the arguments within get_terms

    By default, all terms without posts are hidden, here is the argument

    'hide_empty'    => true, 
    

    To retrieve terms without posts, you'll need to pass false to the hide_empty argument, like this

    $terms = get_terms( 'hide_empty=false' );