WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm requesting the wordpress function if (email_exists($email)) { ... } from a file (email_check.php) via ajax. Using this function is causing a server error though.

The origin (from an input text field):

var check = $('#email-input');
var email = check.val();
    url: "email_check.php",
    data: {'email' : email},
    type: "GET",
    dataType: 'json',
    success: function(data) {
        if(data.result) {
            alert('Email exists!');
        else {
            alert('Email doesnt!');
    error: function(data){


$email = $_GET['email'];
if ( email_exists($email) ) {$response->result = true;} else {$response->result = false;}
echo json_encode($response);    

This results in no alert taking place. By going directly to check_email.php?email=email@address.com it give me a server error page. I also replaced email_exists($email) with the same direct email entered as the url param and it does work.

Does anyone know why this is?

share|improve this question
up vote 0 down vote accepted

This happens because the PHP file you are using has no connection to WordPress, the function is never loaded. Use the built-in AJAX-API instead, and it will work fine.

share|improve this answer
Ah, makes sense. Would it not work to simply reference where the function is? Or not good practise? – zilj Oct 17 '12 at 15:38
Most WordPress files require other WordPress files to be included without an error. In the end you would include almost as many files as the AJAX file already does. – toscho Oct 17 '12 at 15:41
Ok thanks a lot. – zilj Oct 17 '12 at 15:42
For anyone else interested, I ended up following w4dev.com/wp/wp_ajax to get it all working. Thanks toscho for the solution. – zilj Oct 17 '12 at 16:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.