Ich muss eine Liste von Kontrollkästchen zu benutzerdefinierten Taxonomie hinzufügen/bearbeiten Formular hinzufügen. Ich habe diesen Code für das Hinzufügen eines Textfeldes für benutzerdefinierte Taxonomie Form in meiner Plugin und es funktioniert gut:WordPress: Kontrollkästchen zur benutzerdefinierten Taxonomie hinzufügen/bearbeiten Formular
<?php
function taxonomy_edit_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option("taxonomy_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e('Term:'); ?></label></th>
<td>
<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr($term_meta['custom_term_meta']) ? esc_attr($term_meta['custom_term_meta']) : ''; ?>">
</td>
</tr>
<?php
}
add_action('product_cat_edit_form_fields', 'taxonomy_edit_meta_field', 10, 2);
function save_taxonomy_custom_meta($term_id) {
if (isset($_POST['term_meta'])) {
$t_id = $term_id;
$term_meta = get_option("taxonomy_$t_id");
$cat_keys = array_keys($_POST['term_meta']);
foreach ($cat_keys as $key) {
if (isset ($_POST['term_meta'][$key])) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
update_option("taxonomy_$t_id", $term_meta);
}
}
add_action('edited_product_cat', 'save_taxonomy_custom_meta', 10, 2);
add_action('create_product_cat', 'save_taxonomy_custom_meta', 10, 2);
Wie ich eine Liste von Kontrollkästchen in der gleichen Art und Weise hinzufügen kann?
Welche Werte von Attributen sollte ich dem Kontrollkästchen Eingabe-Tag (Name, Wert) hinzufügen? Wie kann ich das überprüfte Feld speichern? Wie zeige ich markierte Kästchen auf der Bearbeitungsseite an? –