0

I need help with a code to customize the category taxonomies in the frontend. It's a code from a plugin:

    // Categories
     $vvc_categories     = wp_get_post_terms( $vvc_id, 'vvc_tax_cat', array( "fields" => "ids" ) );

    $out .= '<label for="vvc_categories">' . esc_html__( 'VVC Kategorien', 'vvc_textdomain' ) . '</label>';
    $out .= '<div class="form-input">';

    foreach ( $vvc_post_categories as $key => $value ) {
        $out .= '<input type="checkbox" name="vvc_categories[]" class="vvc_categories" id="vvc_categories" multiple="multiple">';
        $selected = ( is_array( $vvc_categories ) && in_array( $key, $vvc_categories ) ) ? ' selected="selected"' :'';
        $out .= '<option type="checkbox" value="' . esc_attr( $key ) . '" ' . $selected . '>' . esc_html( $value ) . '</option>';
    }

    $out .= '</input>';// .vvc_categories
    $out .= '</div>'; // .form-input

I changed the type from "select" to "checkbox". More precisely I changed "select" to "input" and added the "type="checkbox"".

As a result I got the checkboxes but when I hit submit the categories were not saved. All worked fine with the select version. Maybe someone got a hind for me. Any help is appreciated

0

1 Answer 1

1

Your select tag doesn't have a name attribute, it only has a type and value. The name is used as an ID when you POST most likely the reason your data isn't saving.

Quick Example:

<form action="/action_page.php">
<select name="cars">
  <option value="volvo">Volvo XC90</option>
  <option value="saab">Saab 95</option>
  <option value="mercedes">Mercedes SLK</option>
  <option value="audi">Audi TT</option>
</select>
<input type="submit" value="Submit">
</form>

<p>Choose a car, and click the "Submit" button to send input to the server.</p>

</body>
</html>

You can run this example here -> Run Example

1
  • But I have no select tag. Thats the point. I changed it to an input tag.. And I have a name attribute in the input tag
    – Tahmo
    Commented Apr 27, 2018 at 19:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.