come in a bit of problem trying to call my function in wordpress ajax.. This is what i have so far if any one can point me in the right direction that would be super...trying to pull my artist feed through an ajax call using a function in my custom.php file im using the ajax functionality in Wordpress for the url
thanks
Custom.php
<?php
function enable_ajax_functionality() {
wp_localize_script(' ajaxify ', ' ajaxify_function ' , arrary(' ajaxurl ' => admin_url (' admin-ajax.php ') ) );
}
add_action(' template_redirect ', 'enable_ajax_functionality');
function test_ajax() {
header( "Content-Type: application/json" );
$args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'artist',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
$posts_array = get_posts($args);
echo json_encode($posts_array);
die();
}
add_action("wp_ajax_nopriv_test_ajax" , 'test_ajax');
add_action("wp_ajax_test_ajax" , 'test_ajax');
Ajax Call
function getFeed() {
console.log(ajaxURL);
jQuery.ajax({
url: ajaxURL,
data: ({action : 'test_ajax'}),
success: function( response ){
console.log( response );
}
});
}