WordPress ajax-action how to return content

OK, so you misunderstood it a little bit, I guess…

You do the first part correctly. So yes – AJAX requests should be sent to wp-admin/admin-ajax.php and the should have action param set in the request (either as a POST or as a GET).

But then, you do it wrong. You register your action with this code:

add_action('beacon_podio-get_apps', array($this, "get_apps"));

But id should be:

add_action('wp_ajax_beacon_podio-get_apps', array($this, "get_apps"));

or (for anonymous users)

add_action('wp_ajax_nopriv_beacon_podio-get_apps', array($this, "get_apps"));

So just to make it clear – the correct hooks are:

  • wp_ajax_(action)
  • wp_ajax_nopriv_(action)

where (action) is the action that you sent as action parameter.