how to use ajax in plugin admin area?

Please, avoid the use of require(‘../../../wp-load.php’); and things like that as suggested in other answers. You should always use the WordPress AJAX way. It is really easy and you will have all WordPress engine loaded in your PHP script. Just three considerations: You have to send the ajax request to …wp-admin/admin-ajax.php. ajaxurl is a javascript … Read more

AJAX Implementation

First, enqueue your script correctly, in functions.php: function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); } add_action(‘wp_enqueue_scripts’, ‘my_enqueue_scripts’); Then, Authenticated users only (see https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_nopriv_(action)) (can also be in functions.php): function fetchData(){ // Not needed anymore, as you manage the case through the `add_action` method // if ( ! is_user_logged_in() ) { // return; // } // this can be … Read more

Is there a hook that fires before an ajax call?

If you look into this file wp-admin/admin-ajax.php where the wp_ajax_ actions are called, you will find that the admin_init action is being called before it. Here is how to return a different json object based on if the user is admin or not: add_action( ‘wp_ajax_testing’, ‘my_ajax’ ); add_action( ‘admin_init’, ‘my_ajax_checker’, 10, 2); function my_ajax_checker() { … Read more

How to implement AJAX post navigation into WordPress?

What you are looking for is AJAX navigation. It’s not that complicated, however it’s not very easy too. I’ve written a simple example for you, I hope it helps you in your case. An AJAX request has 2 steps, first a front-end request that is sent out by browser when for example a user clicks … Read more

How is it possible that the function of the test page works, but it does not go live?

Try changing your script to this since you’re not actually running a cross-browser request: <script> (function($) { $(document).ready(function() { var refreshId = setInterval(function() { $(‘#content’).fadeOut(“fast”).load(‘/new.php’).fadeIn(“fast”); $(“#content .span9 article”).unwrap(); }, 10000); }); })(jQuery); UPDATE: Wrapped in WP-friendly jQuery no-conflict code…

Automatically pull newer posts and append to current page.

I was in the same situation as you recently. The way I did it is probably wrong, and prone to bugs but if you can live with that then this might help. Basically you create an empty array at the top of your loop file, say for example loop-index.php. $ignores = array(); Then inside your … Read more

How to modify wp_ajax function?

You can jump in front of an AJAX hook by specifying a higher priority (i.e. lower number), like this: add_action( ‘wp_ajax_find_posts’, ‘wp_ajax_find_posts’, 0 ); NB: works because 0 < 1