Answer the question
In order to leave comments, you need to log in
How to synchronize data of two tables wp_users and wp_2_users?
It is necessary that registration go to two tables wp_users and wp_2_users.
That is, if they registered on one site, then he could go to another.
Tables in one database, you only need to write a mysqli query, when catching registration, but I can't catch up with what to write there...
And how to write wp_usermeta to wp_2_usermeta?
Answer the question
In order to leave comments, you need to log in
I did it this way, I add it to the data when registering a new user in another table, I don’t forget about the usermet and everything works as it should.
add_action( 'user_register', 'crf_user_register' );
function crf_user_register( $user_id ) {
if ( ! empty( $_POST['user_expiration_date'] ) ) {
$hours = $_POST['user_expiration_date'];
$date = date('Y-m-d H:i:s', strtotime("+".$hours." hours"));
update_user_meta( $user_id, 'user_expiration_date', $date );
$connect = mysqli_connect('localhost', 'пользователь', 'пароль', 'база данных');
$usersinsert = mysqli_query($connect, "INSERT INTO wp_1_users SELECT * FROM wp_users WHERE ID = $user_id" ); // данные из wp_user в wp_1_users
$usersmetainsert = mysqli_query($connect, "INSERT INTO wp_1_usermeta SELECT * FROM wp_usermeta WHERE user_id = $user_id" ); // данные из wp_usermeta в wp_1_usermeta
$usersmetaupdate = mysqli_query($connect, "UPDATE wp_1_usermeta SET meta_key = 'wp_1_capabilities' WHERE meta_key = 'wp_capabilities'" ); // Чтобы обновлялась роль пользователя
}
}
The simplest of crutches, to make one of the tables a view of the form:
SELECT * FROM otherbd name.othertable name;
As a result, this view will be updated, and it will be possible to insert and read from it in the same way as from the base table (all changes will fall into the original one), but the WordPress engine most likely will not even notice that this is not a full table, but its display.
This is provided that they are stored on the same server, of course.
Ready to put a case of beer, that your task is solved in a slightly different way. See my answer in your other question: How to make wordpress registration in two tables?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question