Hi,
Your options
key should have an associative array as its value:
wpas_add_custom_field( 'Product2', array('required' => true, 'field_type' => 'select', 'title' => 'Product2', 'label' => 'Product2', 'label_plural' => 'Products','options' => array( 'my_value' => 'My Value', 'another_value' => 'Another Value' ) ) );
Yes thks i know that, but can i insert variable like this :
wpas_add_custom_field( 'Product2', array('required' => true, 'field_type' => 'select', 'title' => 'Product2', 'label' => 'Product2', 'label_plural' => 'Products','options' => array( 'my_value' => '$value1', 'another_value' => '$value2' ) ) );
Thks !
You can certainly use variables. You shouldn’t wrap them inside ''
however. Simply use 'my_value' => $value1
Yes off course sorry !
But how insert variable coming from array ?
I not very good in php 😀 Sorry !
Example :
‘$values’ is a array.
wpas_add_custom_field( 'Produit', array('required' => true, 'field_type' => 'select', 'title' => 'Produit', 'label' => 'Produit', 'label_plural' => 'Produits','options' => $values));
The select is ok, but not the value (return key to array and not the value)…
I don’t know if i am understanding sorry 😀
I think I found …
$valuesname = array_combine(array_keys(array_flip($values)), $values);
wpas_add_custom_field( 'Produit', array('required' => true, 'field_type' => 'select', 'title' => 'Produit', 'label' => 'Produit', 'label_plural' => 'Produits','options' => $valuesname));
😀
In your example above, as long as $value
is an associative array formed as 'my_value' => 'My Value'
it should work.
# Example
$values = array( 'my_value' => 'My Value' );
wpas_add_custom_field( 'Produit', array('required' => true, 'field_type' => 'select', 'title' => 'Produit', 'label' => 'Produit', 'label_plural' => 'Produits','options' => $values));