php


get_terms gives “invalid taxonomy” from plugin


I'm building a plugin for woocommerce and i have some troubles. I'm trying to get all avalible product categories.
the code simply looks like this:
$cats = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>0));
print_r($cats);
This gives me
WP_Error Object
(
[errors:WP_Error:private] => Array
(
[invalid_taxonomy] => Array
(
[0] => Invalid taxonomy
)
)
[error_data:WP_Error:private] => Array
(
)
)
Do i need to hook this to some special init or something? I tried the same code in functions.php but with the same error.
EDIT:
Yep, i found a soluiton to the problem. I added
add_action('init', 'runMyPlugin');
did the trick!
Just adding a full code example
add_action('init', 'my_get_woo_cats');
function my_get_woo_cats() {
$cats = get_terms( array( 'taxonomy' => 'product_cat','hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>0) );
print_r($cats);
}

Related Links

Laravel unable to load FFProbe?
Conditional if statement not working php versions
Build an associative array from a SQL SELECT JOIN (PHP)
What causes 'error:1408D172:SSL routines:SSL3_GET_KEY_EXCHANGE:wrong signature type' SSL error?
Query data displays locally in MySQL, but query in PHP is blank
creating a random string without duplicate characters php
PHP: How to check if a number is between collection of two numbers
WordPress multiple content sections
Image carousel with SQL [closed]
Angular + Phonegap + WordPress Post Request Failing
Inserting data into a table and then reading that data and inserting it into another table
Doctrine says primary key is not defined when column is both PK and FK
php cron jobs from cpanel is not working. No error in email
Using text() to match custom entity names in XSLT
Flot with json and php
PHP, add temporary only value into array

Categories

HOME
apache-nifi
hdfs
openlayers-3
mongoid
dependencies
material-components
bittorrent
cdi
joomla3.2
xades4j
lapack
alljoyn
feature-extraction
sslhandshakeexception
freertos
amazon-elb
sonata
complexity-theory
squid
django-rq
corona
twisted
pickle
boomi
azure-machine-learning
tableview
fido-u2f
sharedpreferences
fusetools
adapter
es6-modules
mapnik
caesar-cipher
knights-tour
mongoengine
cmis
textmate2
newtons-method
hypothesis-test
dbcc
sony-future-lab-n
jgrapht
ndk-build
mathjs
zynq
maven-release-plugin
piping
ajaxmin
timestamping
seadragon
ui4j
blank-line
postal-code
cache-manifest
erlog
python-curses
fiware-bosun
debug-symbols
fat32
famo.us
dc
adwords-apiv201402
rails-api
gpu-programming
nosql-aggregation
typesafe-stack
visual-c++-2005
colon
libxml-js
hints
dibs
multiple-dispatch
wndproc
border-box
system-information
algol68
fbml
microblogging
jdownloader
mysqli-multi-query
firephp

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile