WordPress admin AJAX request always return 0 even with die()

WordPress offers a great way for theme and plugin developers to add functionality using AJAX and with the use of their API your theme and plugin works smoothly but wait what this AJAX mean? AJAX is stands for Asynchronous JavaScript and XML and AJAX is not a new programming language, but a new way to use existing standards, okay so much for that.

So you’re working in Worpress AJAX huh? Last week I’m working on my plugin and I’m using AJAX on it, all fine the code, the callback function, everything and I began to scratch my head, why I only got zero response? Luck for you mate I will share you the fix.

Solution 1:

Make sure that you’re calling the action properly in your PHP file, a sample action declaration inside in your JS file.

JS File

PHP File

To add the action please see below, notice the word ACTION after wp_ajax_ and wp_ajax_nopriv

That mean we allow with privilege or no privilege users.

Solution 2:

This is the most common mistakes ever; please don’t forgot to include the PHP file in your plugin or theme init 😉

by Ryan Sutana

  • Neocsatornaja

    I have a funcktion which get the new post in ajax:

    (function($) {

    $(document).ready(function() {

    var refreshId = setInterval(function()



    }, 30000);



    And the php part:


    When i set the permalinks type to %postname% the function return 404,but if I set the link type to default,function is work.

    Can you help me solve this problem?

    • Hi,

      Just want to know if you’re using wp_localize_script() to use admin-ajax.php in front-end? if so then try this

      $(‘#content’).load( theme_ajax.them_url + ‘new.php’ );
      // theme_ajax localize object name
      // theme_url the localize theme url

      $(‘#content’).load( /’new.php’ );

      // this option if you’re adding script file inside PHP file

      What we really change here is just the .php file path to directly call it in your theme file.

      Hope that helps

      • Neocsatornaja

        I’m not use this,jut I puted my index.php with .
        So how can i do it?:D
        Sorry I’m full stupid for this:D

        • Use the option 2, btw you’re using WordPress?

          • Neocsatornaja


          • Neocsatornaja

            Waiet a minute.
            The option not refresh the page in jquery.
            If you see my function,you see my refresh every 30 second.

          • Glad it works now

  • Hi I’m confuse on what really you’re trying to achieve also I can’t be more helpful on non-related to my posts 😉

    • Neocsatornaja

      You are right,sorry for the Off topcihes,just I don’t know,who can help me?
      I mean, I tryed stackoverflow,but there kick out these quetions,they sayed this quetion too local or this comerical plugin,they don’t help me:(
      What I want:
      If you seed the link, you can see notifications.
      And i’d like to integrate these for my wordpress.
      That’s becouse, these awsome!
      Think about is!
      You can get notification everythink wich you’re intrested, just like facebook.

      • This can also be done using FeeBurner subscription and every time you add posts your viewer automatically received email message.

  • Tekeste Gebreanenia

    I just spent almost an hour trying to figure this out! It was because I didn’t include the file 🙁 . Thank you for the reminder.