I have a registration form in my wordpress site. The following is the code that i have used for register users.
$username = $wpdb->escape(trim($_POST['txtFullName']));
$email = $wpdb->escape(trim($_POST['txtEmail']));
$password = $wpdb->escape(trim($_POST['txtPassword']));
$confirmpassword = $wpdb->escape(trim($_POST['txtConfirmPassword']));
gender = $wpdb->escape(trim($_POST['gender']));
$user_id = wp_insert_user( array ('user_pass' => apply_filters('pre_user_user_pass', $password), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'author' ) );
$authid = $user_id;
do_action('user_register', $user_id);
// Insert into Post table
$post = array();
$post['post_author'] = $authid ;
$post['post_date'] = date('Y-m-d H:i:s') ;
$post['post_date_gmt'] = date('Y-m-d H:i:s') ;
$post['post_name'] = $username ;
$post['post_status'] = 'pending' ;
$post['post_title'] = $username ;
$post['post_type'] = 'post';
$post['post_category'] = $gender;
wp_insert_post( $post, $wp_error );
I am trying to insert the user in the posts table too after registered. If i entered the username like test'name it will be inserted as testname in user table but it will be inserted as test\'name in posts table. I have to remove the quotes in posts table too. How to do that?
You can remove quotes or any character with str_replace()
matching to your example: