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?

  • 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 May 2 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 May 2 at 13:33
  • You need to make sure the code runs after the taxonomies are registered. This normally happens on init. – Jacob Peattie May 2 at 14:24
-1

You can try this :

add_action( $terms.'_add_form_fields', '___add_form_field_term_meta_text' );
  • This works also, but the prob was me using get_object_taxonomies in a plugin file. Which returns an empty array. Know how to get that working? – Silvester Vella May 2 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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