WordPressのカテゴリーは、通常は複数選択できるようになっています。
しかし場合によってはカテゴリーの選択を1つに制限したいケースがあります。
カテゴリー選択をドロップダウン形式にして入力を1つに制限
functions.php に以下のコードを記述します。
function customize_category_select() { ?>
<script>
var options=[];
jQuery(function($){
$( "#categorychecklist label" ).each(function(){
options.push( '<option value="' + $(this).children("input").val()+ '">' + $(this).html().replace(/<input[^>]+>/g, '') + '</option>' );
});
$( "#categorychecklist" ).replaceWith( '<select id="categorychecklist" name="tax_input[category][]" style="width:100%; margin:10px 0; ">' + options.join( '' ) + '</select>' );
});
</script>
<?php
}
add_action( 'admin_print_footer_scripts', 'customize_category_select' );
コピペで簡単に使えます。
ぜひご利用ください。