I encountered a problem trying to make a select button comprising options of custom post type taxonomies (terms, taxonomies, not sure about proper nomenclature?).

So, the function:

$terms = get_terms(array(
    "hide_empty" => false,

foreach ($terms as $term) {

    echo "<li>".$term->name."</li>";

Whenever I call the function without stating “taxonomy” parameter (plain function, as above) it’s working fine displaying all WordPress taxonomies including those for my custom post type.

When I include "taxonomy" => "category" in get_terms() arguments array it gives me list of native post categories, for "taxonomy" => "post_tag" it displays all pos tags names but when I change it to "taxonomy" => "my_custom_taxonomy" (which is being displayed just fine among other taxonomies when I don’t include "taxonomy" parameter at all, just as I mentioned above) it returns Notice: Trying to get property of non-object in C:XAMPPhtdocs........php on line xx

Why is it happening and is there a simple workaround to this?

All help will be much apprieciated! Thanks.

Read more here: Why get_terms() behaves strangely when being called in admin (for use in meta box)?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: