I've created a basic script in my wordpress root folder as a temporary file to generate a batch of new posts.
I've included the line:
require_once("wp-load.php");
As I've done in the past.
I'm encountering problems that certain taxonomies are not seemingly available in this PHP script when calling e.g.
$productterms = get_terms( array( 'taxonomy' => 'product-type', 'parent' => 0 ) );
I get a response of invalid-taxonomy.
The taxonomy name is definitely correct and this call to retrieve the terms works in functions.php.
I suspect I have a load order issue - but can anyone suggest how to work around this? Essentially I just need to have a PHP script that will allow me to loop through an array I've compiled to create pages based on that data - but I need the various taxonomies loaded/available to use.
I've created a basic script in my wordpress root folder as a temporary file to generate a batch of new posts.
I've included the line:
require_once("wp-load.php");
As I've done in the past.
I'm encountering problems that certain taxonomies are not seemingly available in this PHP script when calling e.g.
$productterms = get_terms( array( 'taxonomy' => 'product-type', 'parent' => 0 ) );
I get a response of invalid-taxonomy.
The taxonomy name is definitely correct and this call to retrieve the terms works in functions.php.
I suspect I have a load order issue - but can anyone suggest how to work around this? Essentially I just need to have a PHP script that will allow me to loop through an array I've compiled to create pages based on that data - but I need the various taxonomies loaded/available to use.
Share Improve this question asked Dec 31, 2019 at 14:51 stevesteve 1176 bronze badges1 Answer
Reset to default 0Probably just use the taxonomy call within wordpress action callback function.
add_action('init', 'my_callback_func');
function my_callback_func() {
//here you can place your get terms
}