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

custom taxonomy - add_action with variable as a part of the $tag string

programmeradmin0浏览0评论

I am trying to create meta fields to multiple custom taxonomy terms. I put the complete code inside a foreach but nothing is working.

$taxs = get_object_taxonomies( 'product' );

foreach($taxs as $terms){  
    add_action( "{$terms}_add_form_fields", '___add_form_field_term_meta_text' );

Is it possible to use the $terms variable like that?

I am trying to create meta fields to multiple custom taxonomy terms. I put the complete code inside a foreach but nothing is working.

$taxs = get_object_taxonomies( 'product' );

foreach($taxs as $terms){  
    add_action( "{$terms}_add_form_fields", '___add_form_field_term_meta_text' );

Is it possible to use the $terms variable like that?

Share Improve this question edited May 2, 2019 at 8:36 kero 6,3401 gold badge25 silver badges34 bronze badges asked May 2, 2019 at 8:04 Silvester VellaSilvester Vella 155 bronze badges 3
  • Yes. It is possible. If it's not working then the issue is probably with your ___add_form_field_term_meta_text function. What does that look like? – Jacob Peattie Commented May 2, 2019 at 8:43
  • the code was fine coz I t worked without the variable. The problem apparently is Im using get_object_taxonomies from a plugin file, which returns an empty array. For now I put in the tax names manually into an array. Do you know how I can get the get_object_taxonomies to work in the plugin files? – Silvester Vella Commented May 2, 2019 at 13:33
  • You need to make sure the code runs after the taxonomies are registered. This normally happens on init. – Jacob Peattie Commented May 2, 2019 at 14:24
Add a comment  | 

1 Answer 1

Reset to default -1

You can try this :

add_action( $terms.'_add_form_fields', '___add_form_field_term_meta_text' );
发布评论

评论列表(0)

  1. 暂无评论