Last active
June 13, 2022 07:18
-
-
Save hieuhuynh93/51c31de2a05f9cf826a17372ff78ac59 to your computer and use it in GitHub Desktop.
Enable comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function enableCommentByCat() { | |
global $wpdb; | |
$getPosts = new WP_Query( array( 'category_name' => 'ten_category') ); | |
if ( $getPosts->have_posts() ) { | |
while ( $getPosts->have_posts() ) { | |
$getPosts->the_post(); | |
$postId = get_the_ID(); | |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open' WHERE ID=$postId")); | |
} | |
} else { | |
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'closed' WHERE post_type='post'")); | |
} | |
} | |
enableCommentByCat(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment