$wpdb->insert Giving duplicates

There is nothing that prevent duplicates here. When you create the table ‘church’ is a good idea set a UNIQUE sql index for field email, in this way you can rely on email address to preventing duplicate entries. As a generic PHP good practice, you should check the existence of a a variable before using … Read more

What should a WordPress developer know about MySQL? [closed]

Questions like this usually yield a lot of discussions, but let me give it a shot: If you’re talking about SQL queries: If you’re only adding content, managing plugins, themes and WordPress updates, there’s a 99.9% chance that you will never need to write a single line of it. I don’t want to put 100% … Read more

Error establishing a database connection problem in xampp saver

WP-CONFIG file should be like below- // ** MySQL settings – You can get this info from your web host ** // /** The name of the database for WordPress */ define(‘DB_NAME’, ‘database_name_here’); /** MySQL database username */ define(‘DB_USER’, ‘username_here’); /** MySQL database password */ define(‘DB_PASSWORD’, ‘password_here’); /** MySQL hostname */ define(‘DB_HOST’, ‘localhost’); /** Database … Read more

Historic WordPress database connection

WordPress still has mysql_query() in its codebase (as of February 27, 2018). mysql_*() was deprecated in PHP 5.5.0 and removed in PHP 7.0.0. Since WordPress still supports PHP 5.2 (for reasons beyond understanding), it needs to support both mysql_*() and mysqli_*(), WordPress will use mysqli_query() when available ( PHP > 5.3.0 ) and fallback to … Read more

Code to remove authors with no posts connected to them

<?php /** * Plugin Name: Delete Non Authors */ function delete_non_authors() { global $wpdb; $non_authors = $wpdb->get_col( “SELECT DISTINCT $wpdb->users.ID FROM $wpdb->users LEFT JOIN $wpdb->posts ON $wpdb->users.ID = $wpdb->posts.post_author WHERE $wpdb->posts.ID IS NULL” ); foreach ($non_authors as $user_ID) wp_delete_user($user_ID); } register_activation_hook(__FILE__, ‘delete_non_authors’); ?> Drop this in a file, name it something like delete-non-authors.php, upload it … Read more

2 WordPress sites with 2 databases but sharing the same users

It’s not possible in WordPress to have shared users between 2 separates installations on 2 separated databases. It could be possible just by hardcoding: hardcode WP_User class connect to other database and retrieve users from there hardcode get_metadata() function, that for wp_usermeta table connect to other database and retrieve users from there but mentioned solution … Read more