jquery - custom wordpress php file relations not recognized -
i trying quiet simple: file /inc/follow-event.php calling ajax post request:
jquery.ajax({ type: "post", data: { data:'asd'}, url: "/wp-content/themes/cust/lib/follow_cat_event.php" }); the file lib/follow_cat_event.php is:
<?php $user = wp_get_current_user(); echo $user->id; ?> and reason, request returns error 500 because follow_cat_event not recognize wordpress functions when included in functions.php:
include "lib/follow_cat_event.php"; edit update:
follow_cat_event.php:
<?php add_action('wp_ajax_my_action', 'my_action_callback'); function my_action_callback(){ global $wpdb; $user = wp_get_current_user(); echo $user->id; if ( isset($_get['data']) ) { } } ?> follow_cat.php:
function myfunction(){ jquery.post( "/wp-content/themes/geektime/lib/follow_cat_event.php", { action: "my_action", data: { data:'asd'}, } ); } still no luck...
even if add together /inc/follow-event.php in function.php, won't able utilize wordpress functions in it. because /inc/follow-event.php in doesn't come under scope of wordpress function. can create plugin & seek way.
also don't forget add together action while implementing ajax wordpress default ajax handler
jquery.ajax({ type: "post", action : "my_action" data: { data:'asd'}, url: "<?php admin_url( 'admin-ajax.php' ) ?>" }); now, add together plugin & activate it.
<?php /* plugin name: wordpress ajax author: abhineet verma version: 1.0 */ function st_24388029(){ // stuff here } add_action( 'wp_ajax_my_action', 'st_24388029' ); add_action( 'wp_ajax_nopriv_my_action', 'st_24388029' ); ?> this allow create ajax request in wordpress frontend well.
php jquery ajax wordpress include
No comments:
Post a Comment