• Resolved johndoe01

    (@johndoe01)


    Greetings.
    Having the documentation on custom fields https://wpadverts.com/documentation/custom-fields/
    I have the following question.

    If in the functions php the field gets added with this parameter:

    $form["field"][] = array(            
            "name" => "condition",
            "type" => "adverts_field_select",
            "order" => 29,
            "label" => "Condition",
            "is_required" => true,
            "validator" =>  array( 
                array( "name" => "is_required" ),
            ),
            "options" => array(
                array("value"=>"New","text"=>"New"),
                array("value"=>"Used","text"=>"Used"),        
                )
             );
        

    How can i add a second item into the resulting array?
    Let me clarify:
    The result field comes into the form as array into the meta of the post with one item into the array.
    'condition => 0 => "New"
    The idea is add into the array a secondary key so i can use it to call such value in the meta to seize the field and extend an additional information piece like this

    array meta comes
    'condition'=>
        0 =>"New",
        1=>"star"

    Am i missing something, or such meta does nnot allow secondary items on such arrays?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter johndoe01

    (@johndoe01)

    Nevermind. I did a workaround in the file (not in the functions), that served my purpose.

    But in order to not let this thread go to waste: How can i set a limit of characters on a text area?

    If you dear reader are asking how i did the workaraound… well i had to place in the php file where will be displayed after the definition of the field:

    <?php
    <?php $my field = get_post_meta( $post_id, "the_field", false ); ?>
    if ($myfield[0]=="value1"){ $display="display-item1";}
    if ($myfield[0]=="value2"){ $display="display-item2";}   
    ... 
    ?> 
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    if you would like to show different option in the <select> and different value on the Ad details page then your options should look like this

    
      array("value"=>"display-item1","text"=>"New"),
      array("value"=>"display-item2","text"=>"Used"), 
    

    Then in [adverts_add] you will see in the dropdown options “New” and “Used” but when viewing the Ad on the Ad details page the actual value will be either “display-item1” or “display-item2”.

    Thread Starter johndoe01

    (@johndoe01)

    OK, even though it was not what i was looking for, I marl this as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Fields – Add to array’ is closed to new replies.