WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] get_terms invalid taxonomy

[Resolved] get_terms invalid taxonomy

  • Topher
    Participant

    @topher1kenobe

    In my theme functions.php I have this code:

    $menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );

    and it works great.

    I have the same code in a plugin and it says this:

    object(WP_Error)#1096 (2) {
      ["errors"]=>
      array(1) {
        ["invalid_taxonomy"]=>
        array(1) {
          [0]=>
          string(16) "Invalid taxonomy"
        }
      }
      ["error_data"]=>
      array(0) {
      }
    }

    Why would context matter? And what can I do about it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Topher
    Participant

    @topher1kenobe

    I figured it out. My test was simply calling my function in the plugin, which was too early in the init. Hooking my function to init made it fire later, and showed me that it was indeed getting the right data.

    @toper
    I am getting the same error…

    WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data] => Array ( ) )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] get_terms invalid taxonomy’ is closed to new replies.