Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am designing a wordpress website with theme options:

In my theme options I have code that looks like this:

    $class = (isset($this->field['class']))?$this->field['class']:'regular-text';

    echo '<ul id="'.$this->field['id'].'-ul">';

    if(isset($this->value) && is_array($this->value)){
        foreach($this->value as $k => $value){
            if($value != ''){

                echo '<li><input type="text" id="'.$this->field['id'].'-'.$k.'" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" value="'.esc_attr($value).'" class="'.$class.'" /> <a href="javascript:void(0);" class="nhp-opts-multi-text-remove">'.__('Remove', 'nhp-opts').'</a></li>';

It displays a text field in my theme options panel, and I am able type in it and save it.

Here is my problem, I changed my code to add a text area with the options, and it looked something like this:

    $class = (isset($this->field['class']))?$this->field['class']:'regular-text';

    echo '<ul id="'.$this->field['id'].'-ul">';

    if(isset($this->value) && is_array($this->value)){
        foreach($this->value as $k => $value){
            if($value != ''){

                echo '<li><input type="text" id="'.$this->field['id'].'-'.$k.'" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" value="'.esc_attr($value).'" class="'.$class.'" /> <textaread id="'.$this->field['id'].'-'.$k.'" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" class="'.$class.'">'.esc_attr($value).'</textarea> <a href="javascript:void(0);" class="nhp-opts-multi-text-remove">'.__('Remove', 'nhp-opts').'</a></li>';

Now when I go to my theme options panel, both boxes are there, but if i type something different in each one and save it. Both boxes are displayed to showing the exact same thing. Is there a way I can fix this?

share|improve this question
    
Please post all code relevant to your Theme options. The question doesn't include enough context to be able to provide an answer. –  Chip Bennett Dec 11 '12 at 16:39
add comment

migrated from stackoverflow.com Dec 11 '12 at 16:32

This question came from our site for professional and enthusiast programmers.

1 Answer

Your input and textarea have the same name and id, so when the data is processed, it's only going to recognise one (probably the last).

Try using different name and id properties, and you should be able to differentiate between the 2.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.