Hi I am trying to have live search which searches for existing emails when a user registers. Below is my jquery script
$("#wjp_register input#user_email").change(function(){
console.log("lol");
var email=$("#wjp_register input#user_email").val();
$.ajax({
type:"post",
dataType : 'JSON',
url:"/wordpress/wp-content/themes/tsf/wpjobboard/job-board/check.php",
data:"email-address="+email,
success:function(result){
if(result==0){
console.log(result);
$(".error").html(" Username available");
}
else{
console.log(result);
$(".error").html("Username already taken");
proceed = false;
}
}
});
});
When i check the response in the developer console, the email is echoed successfully but the wordpress get_user_by doesnt seem to work.
My php script
<?php
$mm = $_POST['email-address'];
if ( isset( $_POST['email-address'] ) && ! empty( $_POST['email-address'] ) ) {
//sanitize the data
$email_addr = trim( strip_tags( stripslashes( $_POST['email-address'] ) ) );
echo $email_addr;//This is printed successfullt
echo "<br>";
//This below part doesnt work :(
if( false == get_user_by( 'email', $email_addr ) ) {
echo "Doesnt exist";
} else {
echo "exists";
}
}
?>
get_user_bydoesn't return boolean... it returns an object of a user. The docs show an example: codex.wordpress.org/Function_Reference/get_user_by===rather than==?resultin your success callback.result==0will never be true because you're not sending0back anywhere. Also, what exactly do you mean when you say that it "doesn't work"? What specifically isn't working? What are you expecting vs what is actually happening? It is a bit unclear if an unexpected value is being returned byget_user_byor if an unexpected value is being sent to the javascript callback.