2
When I make an AJAX request in Wordpress I do it in two ways, but I would like to know which is the best.
The two I know are:
1º) You put your function in functions, for example:
add_action('wp_ajax_nopriv_my-function','my_function');
add_action('wp_ajax_busca-my-function','my_function');
function my_function(){
//code
}
2nd) You create a file, call in it the Wordpress functions by wp-blog-header and make the return.
So, is there any other way? Which one would be better? I’m developing a news portal, and the idea is to have a timeline like Stack Overflow, where every new news the customer is notified to update.
When I used functions, it occurred on some servers gives error 404(not found) or 505.. But out of nowhere returned to normal, already went through this?
– Mateus Carvalho
No, I’ve never seen... how do you mount the URL’s
admin-ajax.php
? . . . And, just remembering, if the functionality you implement has to survive if you change from Theme, then one should use a plugin instead of putting infunctions.php
.– brasofilo