I wanted to know if there is a way to use function like query_post() in an ajax call ?
Let's say i'm calling the file _inc/ajax.php
I want to be abble to use the wordpress functions, but i don't know why. Can someone help me for that ?
Thanks a lot :)
You have to create you function in your themes functions.php Here is the example for load popular posts using ajax
I highly recommend the JSON API plugin: http://wordpress.org/extend/plugins/json-api/. It provides a RESTful interface for the most common WordPress functions including
query_post
and allows you to add your own actions.WordPress provides an Ajax Url that you should use along with a complete Ajax API.
You need to create a jQuery function.
Example:
The ajaxurl var is always available on the admin side. If your using it on the front end you need to define it.
Then a PHP function where you can run your query. The PHP function must get attached to the
wp_ajax_your_action
action.Example:
The
wp_ajax_your_action
action is for admin if you need to use it on the front end the action would bewp_ajax_nopriv_your_action