0

我有这个功能,它给了我下拉选项:

public function edit_tax_image_field( $term ){
    $term_id = $term->term_id;
    $term_meta = get_option( "taxonomy_$term_id" );
    $image = $term_meta['tax_image'] ? $term_meta['tax_image'] : '';
?>
    <tr class="form-field">
        <th scope="row">
            <label for="term_meta[tax_image]">Dropdown menu</label>
            <td>
                <select name="term_meta[tax_image]" id="term_meta[tax_image]" style="width: 300px;">
    <?php
        $selected = $image;
        $p = '';
        $r = '';

        foreach ( _s_sample_select_options() as $option ) {
            $label = $option['label'];
            if ( $selected == $option['value'] ) // Make default first in list
                $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
            else
                $r .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $option['value'] ) . "'>$label</option>";
        }
        echo $p . $r;
    ?></select>
                <p class="description">Some description.</p>
            </td>
        </th>
    </tr><!-- /.form-field -->
<?php
} // edit_tax_image_field

这是我的储蓄功能

public function save_tax_meta( $term_id ){

    if ( isset( $_POST['term_meta'] ) ) {

        $t_id = $term_id;
        $term_meta = array();

        $term_meta['tax_image'] = isset ( $_POST['term_meta']['tax_image'] ) ? esc_attr( $_POST['term_meta']['tax_image'] ) : '';

        // Save the option array.
        update_option( "taxonomy_$t_id", $term_meta );

    } // if isset( $_POST['term_meta'] )
} // save_tax_meta

我不知道,应该是哪里的bug。我是编码初学者,所以......错误可能很简单。

解决这个问题花了我一天的时间 :D 仍然没有解决方案 :(

4

1 回答 1

0

尝试改变

if ( $selected == $option['value'] ) // Make default first in list
                $p = "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";

if ( $selected == $option['value'] ) // Make default first in list
                $p .= "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $option['value'] ) . "'>$label</option>";
于 2013-10-11T10:18:02.800 回答