Help us understand the problem. What is going on with this article?

[WordPress]タームにカスタムフィールド追加

More than 1 year has passed since last update.

最新のバージョンは対応したか知らんけど
Advance Custom Fieldsだとwp_termmetaに保存しなくて
まあまあ不便だったので自前でやる。

functions.php
//新規
add_action('{taxonomy}_add_form_fields', function() {
    $format = '<div class="form-field"><label for="%1$s">%2$s</label><input type="text" name="%1$s" id="%1$s" value="" size="40"></div>';
    printf($format, '{slug}', '{label}');
});
add_action('create_term', function ($term_id) {
    if ( array_key_exists('{slug}', $_POST) ) update_term_meta($term_id, '{slug}', esc_attr($_POST['{slug}']));
});

//編集
add_action('{taxonomy}_edit_form_fields', function ($term) {
    $format = '<tr class="form-field"><th><label for="%1$s">%2$s</label></th><td><input type="text" name="%1$s" id="%1$s" value="%3$s" size="40"></td></tr>';
    $value = get_term_meta($term->term_id, '{slug}', true);
    printf($format, '{slug}', '{label}', esc_attr($value));
});
add_action('edit_terms', function ($term_id) {
    if ( array_key_exists('{slug}', $_POST) ) update_term_meta($term_id, '{slug}', esc_attr($_POST['{slug}']));
});

inputのtypeやらsizeやらは適宜変更。
フォーマットはどこかしらから引っ張ってこれそうだけども。

ki6ool
絶対ワードプレス使うマン
https://6oolab.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away