0

I'm trying to build a PHP function that creates a drop down inside an array. The theme I'm using gave me an example on how to add custom data to fields and I'm trying to then modify that to add a drop down menu. I'm not even sure if it's possible. The code I have creates the drop down box but doesn't have any data in it.

Here is my code:

function frontend_add_timezone_field( $fields ) {
    $fields['job']['timezone'] = array(
      'label'       => __( 'Your Timezone', 'job_manager' ),
      timezone        => array('(GMT-10:00) Hawaii', '(GMT-09:00) Alaska', '(GMT-08:00) Pacific Time (US & Canada)' ),
      'priority'    => 7
  ); 
 echo '<select name="timezon">';
   for($i = 0; $i < count($timezone);$i++)
    {
        echo '<option value="'. ($i + 1) .'">' .$timezone{$i} . '</option>';
    }
 echo '</select>';
}

Any tips would be greatly appreciated, thanks!

3
  • Where is the value for $timezone established? It seems to me that this might require more experimentation on your part. Commented Jul 15, 2016 at 15:40
  • I thought I was establishing it right there within the array.. am I not able to do that? Commented Jul 15, 2016 at 15:45
  • It was established as a key name for the array. See Sarah's answer below. Commented Jul 15, 2016 at 15:52

1 Answer 1

3

As gladiola commented there is missing $timezone. You have established it inside $fields['job']['timezone']. In other words $timezone is in your case

$timezone = $fields['job']['timezone']['timezone'];

After this the code works for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for all your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.