Home  >  Article  >  CMS Tutorial  >  Turn on and off the WordPress article comment function in batches

Turn on and off the WordPress article comment function in batches

藏色散人
藏色散人forward
2019-10-30 11:47:252541browse

The following column WordPress Tutorial will introduce to you how to turn on and off the WordPress article comment function in batches. I hope it will be helpful to friends in need!

Turn on and off the WordPress article comment function in batches

#WordPress cannot turn on and off the comment function of articles in batches by default. If you want to temporarily turn off or turn on the comment function of WordPress articles, you can refer to the method in this article.

This article uses the WordPress database to operate the WPDB object ($wpdb) to perform batch operations on the comment function of the article.

Add the following code to the current theme functions.php:

Turn on the comment function of articles in batches

global $wpdb;
$wpdb->query( "UPDATE wp_posts SET comment_status='open'" );

Close the comment function of articles in batches

global $wpdb;
$wpdb->query( "UPDATE wp_posts SET comment_status='close'" );

After adding the code, just refresh any page of the website. Remove the code after use and do not need to keep it in the theme.

The above is the detailed content of Turn on and off the WordPress article comment function in batches. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete