0

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.

1 Answer 1

0

Probably 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 

}
4
  • Add this to my stand-alone script or to functions.php? Thanks for replying.
    – steve
    Commented Dec 31, 2019 at 16:40
  • Well in that case you can give a try in your custom scripts. Commented Dec 31, 2019 at 16:53
  • It does work in functions.php (which worked in that context before) - however nothing happens putting that in my standalone php file
    – steve
    Commented Dec 31, 2019 at 17:32
  • It did work - I forgot to add the switch_to_blog() call as this is a multi-site. Now works fine. Thanks.
    – steve
    Commented Dec 31, 2019 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.