最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Script to generate pages - taxonomies not loaded

programmeradmin5浏览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.

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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 

}
发布评论

评论列表(0)

  1. 暂无评论