ajax stopped working when not logged in?

Edit: I’ve kept my original answer below, however, I’m not sure what I was thinking… You should never need to trigger do_action( 'wp_ajax...' ).

While I can’t be sure what the issue is, is the code in the question is roughly ok (I think $_POST should be $_GET with .getJSON).


Try putting this at the top…

if(isset($_REQUEST['action']) && $_REQUEST['action']=='filter_schools'):
        do_action( 'wp_ajax_' . $_REQUEST['action'] );
        do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
endif;

I think WordPress does not automatically do ajax actions for users not logged-in. Potentially non-users could things they are not suppose to be able to do.

I would probably change those $_GETs & %_POSTs to $_REQUEST too.

Leave a Comment