Resetting comment count

Try this code: WARNING: THIS IS JUST PSEUDOCODE! $entries = $wpdb->get_results(“SELECT * FROM wp_posts WHERE post_type IN (‘post’, ‘page’)”); foreach($entries as $entry) { $post_id = $entry->ID; $comment_count = $wpdb->get_var(“SELECT COUNT(*) AS comment_cnt FROM wp_comments WHERE comment_post_ID = ‘$post_id’ AND comment_approved = ‘1’”); $wpdb->query(“UPDATE wp_posts SET comment_count=”$comment_count” WHERE ID = ‘$post_id'”); } Or you might want … Read more

Creating 20,000 Posts or Pages using a .csv file?

Import posts from a .csv file with WP-CLI If our import.csv is tab delimited, with two columns: Planet Mars The red planet. Planet Earth Our blue planet. then we can parse it with help of this answer, where we use IFS=$’\t’ instead as tab delimiter: while IFS=$’\t’, read col1 col2; \ do \ echo “$col1|$col2”; … Read more

Set page template for all pages?

EDIT As noted in the comments on your question, the best approach would just be to edit your page.php file. If you want ALL of your pages to have the same page template, and not have to do anything extra to set it that way, it’s quite obvious why this is a good idea. 🙂 … Read more

Restoring WordPress posts from database only

Re-install a new copy of wordpress and then put in the credentials to your database in the new install. If you install wordpress and try to load the domain with no database attached, it will start the site creation wizard. Just enter the correct database credentials (username, database name, password, and location) and it will … Read more

Can i use php sql functions instead of $wpdb?

There are a few different reasons. 1. Separation of Concerns Fundamentally, your logical code (i.e. your plugin or your theme) should not need to know anything about the database. At all. Really. The $wpdb object is the global database access layer, and you should be using it for all of your database access. If you … Read more