I am trying to write some code to retrieve wordpress posts to jquery using Ajax
I am just learning so have been alerting to the screen. This is what i have so far:
test.js
jQuery(document).ready(function($){
var test_name = "testname";
$.ajax({
url:'/wp-content/plugins/myPlugin/test.php',
data: {name:test_name},
type: 'POST',
cache: false,
success: function(data){
alert(data);
},
error: function(data){
alert('something went wrong');
}
});
});
test.php
<?php
$post_args = array(
'post_type' => 'products',
'numberposts' => -1
);
$myProducts = get_posts($post_args);
echo $myProducts;
?>
Can someone point me in the right direction, I can receive strings back from the test.php, so i know the test.php file is being processed. Thank you for any help/explanations