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

Turn on and off the WordPress article comment function in batches

藏色散人
Release: 2019-10-30 11:47:25
forward
2645 people have browsed it

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'" );
Copy after login

Close the comment function of articles in batches

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

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template