Title: Insert variable php in wpas_add_custom_field
Last modified: August 31, 2016

---

# Insert variable php in wpas_add_custom_field

 *  Resolved [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/)
 * Hello !
 * Can we insert variable php in custom : wpas_add_custom_field ?
 * Example :
 * wpas_add_custom_field( ‘Product2’, array(‘required’ => true, ‘field_type’ => ‘
   select’, ‘title’ => ‘Product2’, ‘label’ => ‘Product2’, ‘label_plural’ => ‘Products’,’
   options’ => array($value)));
 * $value is like : ‘option1’ => ‘First Option’, ‘option2’ => ‘Second Option’
 * Thks !
 * [https://wordpress.org/plugins/awesome-support/](https://wordpress.org/plugins/awesome-support/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [julien731](https://wordpress.org/support/users/julien731/)
 * (@julien731)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370938)
 * 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' ) ) );
       ```
   
 *  Thread Starter [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370954)
 * 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 !
 *  Plugin Author [julien731](https://wordpress.org/support/users/julien731/)
 * (@julien731)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370956)
 * You can certainly use variables. You shouldn’t wrap them inside `''` however.
   Simply use `'my_value' => $value1`
 *  Thread Starter [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370958)
 * Yes off course sorry !
 * But how insert variable coming from array ?
 * I not very good in php 😀 Sorry !
 *  Thread Starter [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370960)
 * 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 😀
 *  Thread Starter [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370963)
 * 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));`
 * 😀
 *  Plugin Author [julien731](https://wordpress.org/support/users/julien731/)
 * (@julien731)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370964)
 * 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));
       ```
   
 *  Thread Starter [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * (@friendlydesign)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370966)
 * Thk you very much !!!!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Insert variable php in wpas_add_custom_field’ is closed to new replies.

 * ![](https://ps.w.org/awesome-support/assets/icon-256x256.png?rev=1849681)
 * [Awesome Support - WordPress HelpDesk & Support Plugin](https://wordpress.org/plugins/awesome-support/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/awesome-support/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/awesome-support/)
 * [Active Topics](https://wordpress.org/support/plugin/awesome-support/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/awesome-support/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/awesome-support/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [friendlydesign](https://wordpress.org/support/users/friendlydesign/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/insert-variable-php-in-wpas_add_custom_field/#post-7370966)
 * Status: resolved