I am creating a plugin for woocommerce and I have some problems. I am trying to get all available product categories.
the code looks something like this:
$cats = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>0)); print_r($cats);
It gives me
WP_Error Object ( [errors:WP_Error:private] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data:WP_Error:private] => Array ( ) )
Does it need to be connected to some special init or something else? I tried the same code in functions.php, but with the same error.
EDIT: Yes, I found soluiton to the problem. I added
add_action('init', 'runMyPlugin');
did the trick!
source share