0

I add function 'listing_companions_Ajax' into $core_actions_post of admin-ajax.php. But discover after WP update that function is not present anymore.

$core_actions_post = array('oembed-cache',...,'listing_companions_Ajax');

Question: how can I add / hook this new function listing_companions_Ajax to the file admin-ajax.php without missing it after an WP update?

jtermaat
  • 31
  • 7

2 Answers2

0

Here is an example for ajax using on WordPress :

This is the javascript.

     $.ajax({
        type: 'post',
        url: siteUrl.ajax_url + '?action=listing_companions_ajax',
        data: someDataHere,
        success: function (response) {
          // do something on success here
        }
 } );

WordPress:

add_action( 'wp_ajax_listing_companions_ajax', 'listing_companions_ajax' );
add_action( 'wp_ajax_nopriv_listing_companions_ajax', 'listing_companions_ajax' );

function listing_companions_ajax() {
 // do smth here
}
Yuxel Yuseinov
  • 344
  • 1
  • 7
-1

Never write a custom code in WordPress code files. If you want to use ajax please consider reading this article - https://codex.wordpress.org/AJAX_in_Plugins. Please let me know if you have further questions.

Yuxel Yuseinov
  • 344
  • 1
  • 7