• Resolved friendlydesign

    (@friendlydesign)


    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/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author julien731

    (@julien731)

    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

    (@friendlydesign)

    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

    (@julien731)

    You can certainly use variables. You shouldn’t wrap them inside '' however. Simply use 'my_value' => $value1

    Thread Starter friendlydesign

    (@friendlydesign)

    Yes off course sorry !

    But how insert variable coming from array ?

    I not very good in php 😀 Sorry !

    Thread Starter friendlydesign

    (@friendlydesign)

    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

    (@friendlydesign)

    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

    (@julien731)

    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

    (@friendlydesign)

    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.