admin管理员组文章数量:1023764
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?
1 Answer
Reset to default -1You can try this :
add_action( $terms.'_add_form_fields', '___add_form_field_term_meta_text' );
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?
-
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
1 Answer
Reset to default -1You can try this :
add_action( $terms.'_add_form_fields', '___add_form_field_term_meta_text' );
本文标签: custom taxonomyaddaction with variable as a part of the tag string
版权声明:本文标题:custom taxonomy - add_action with variable as a part of the $tag string 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745532577a2154816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
___add_form_field_term_meta_text
function. What does that look like? – Jacob Peattie Commented May 2, 2019 at 8:43init
. – Jacob Peattie Commented May 2, 2019 at 14:24