Reputation: 225
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";
}
}
?>
Upvotes: 2
Views: 1110
Reputation: 602
So here is the correct way to use WP from an external file:
Include wp-blog-header.php if you need all of WP and want to fire all of the default hooks and actions.
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
Includ wp-load.php if you only need the WP functions. It doesn't call wp() or invoke the template loader. So it's more lightweight!
define('WP_USE_THEMES', false);
require('./wp-load.php');
Upvotes: 1