ajax in wordpress return content-none file
-
In my funcitons.php file i have function that response to ajax call and return posts:
functions.php:function returnPosts(){ if ( have_posts() ) { while ( have_posts() ) { the_post(); get_template_part('content', get_post_format()); } } else { get_template_part( 'content', 'none' ); } exit(); } add_action('wp_ajax_returnPosts', 'returnPosts'); add_action('wp_ajax_nopriv_returnPosts', 'returnPosts');
Javascript (in index.php):
jQuery.ajax({ type:"POST", url: "<?php echo admin_url("admin-ajax.php"); ?>", data: {"action": "returnPosts"}, success:function(results){ // Work with results } });
But when i call this function via JS i always get content from content-none.php file.
- The topic ‘ajax in wordpress return content-none file’ is closed to new replies.