■参考サイト
http://design-matome.com/archives/90
上記参考サイトのコードを利用すると、デフォルト投稿画面で親カテゴリのチェックボックスを選択禁止にできます。
しかし、下記functions.php 6行目以降の $taxonomy をカスタムタクソノミーのスラッグにすると、カスタム投稿タイプの投稿画面で親カテゴリ (ターム) を選択禁止にはできません。
※下記functions.php 6行目以降の「tokyo」はカスタムタクソノミーのスラッグ
※「tokyo」はカスタム投稿タイプ「area」に属する
デフォルト投稿同様に、カスタム投稿タイプの投稿画面で親カテゴリ (ターム) のチェックボックスを選択禁止にするための助言を頂けませんでしょうか。
どうぞよろしくお願い致します。
▼functions.php
php
1require_once(ABSPATH . '/wp-admin/includes/template.php'); 2class Danda_Category_Checklist extends Walker_Category_Checklist { 3 function start_el(&$output, $category, $depth, $args, $id = 0) { 4 extract($args); 5 if (empty($taxonomy)) 6 $taxonomy = 'tokyo'; 7 if ($taxonomy == 'tokyo') 8 $name = 'tokyo'; 9 else 10 $name = 'tax_input['.$taxonomy.']'; 11 12 $class = in_array($category->term_id, $popular_cats) ? ' class="popular-category"' : ''; 13 $cat_child = get_category_children($category->term_id); 14 if ($cat_child !== "") { 15 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked(in_array($category->term_id, $selected_cats), true, false) . disabled(empty($args['disabled']), true, false) . ' /> ' . esc_html(apply_filters('the_category', $category->name)) . '</label>'; 16 } 17 else { 18 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked(in_array($category->term_id, $selected_cats), true, false) . disabled(empty($args['disabled']), false, false) . ' /> ' . esc_html(apply_filters('the_category', $category->name)) . '</label>'; 19 } 20 } 21} 22 23function lig_wp_category_terms_checklist_no_top($args, $post_id = null) { 24 $args['checked_ontop'] = false; 25 $args['walker'] = new Danda_Category_Checklist(); 26 return $args; 27} 28add_action('wp_terms_checklist_args', 'lig_wp_category_terms_checklist_no_top');
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。