投稿日:2017/03/02
更新日:2017/11/16
functionsフォルダの中の__setting.phpに 以下記述。
———————————————————-
function replace_comment_status($data, $postarr){
if(isset($postarr[“post_category”]) && in_array(“2”, $postarr[‘post_category’], true)) {
$data[‘comment_status’] = ‘open’; }
return $data;
}
add_filter(‘wp_insert_post_data’, ‘replace_comment_status’, ’99’, 2);
———————————————————-
in_array(“2”, $postarr[‘post_category’], true)は
カテゴリIDが2だった場合、コメント欄を設ける ということです