Users select/insert | wpdb |

Hi All,

It’s my first time since a very, very long time using wordpress again and I have some issues with a function I want to create to automate a cronjob.

I’m trying to select the users i have from wp_users table and insert a few values into another table on the same database, but different table (users).

I’ve got so far with this code, but when i run it nothing happens. Not even an error.

Any suggestions are welcomed. Thank you

function wp_users_table_bind(){
global $wpdb;
$secret = mksecret();
$added = time();

$result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}users" );

foreach( $result as $results ){
$name = $results['user_login'];
$passhash = $results['user_pass'];
$email = $results['user_email'];

$wpdb->query("INSERT INTO users (username, passhash, secret, email, status, added) VALUES ($name, $passhash, $secret, $email, $status, $added) 
username = $name,
passhash = $passhash,
secret = $secret,
email = $email,
status = $status,
added = $added");


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer