-2
我有Ajax調用用於獲得響應,響應文件我已經使用WordPress的循環USNG WP_Query()類... 但是當我執行Ajax返回致命錯誤: 致命錯誤:類 'WP_Query' 用C未找到:\ XAMPP \ htdocs中\ businessfinder \可溼性粉劑內容\主題\ businessfinder \ metabox \上線Ajax的process.php 20AJAX調用 - 不承認WordPress的功能/班
這裏是AJAX調用代碼:
var path = 'http://localhost/business-finder/wp-content/themes/businessfinder/metabox/ajax-process.php';
$.ajax({
type: "POST",
url: path,
data: { param:folio_data }
}).done(function(msg) {
$('#ajax_folio').html(msg);
//alert("Data Saved: " + msg);
});
這裏是res龐塞文件代碼:
<?php
print_r($_POST['param']);
if(!empty($_POST['param'])):
echo spyropress_get_attached_posts1($_POST['param'], 'ait-grid-portfolio');
echo '<br><br>';
endif;
function spyropress_get_attached_posts1($post_id = '', $post_type = ''){
//if($post_id = '' || $post_type = '') return;
$counter = 0;
global $wp_query ;
$query = new WP_Query(array('post_type' => $post_type, 'post__in' => $post_id));
if($query->have_posts()):
$out .= '<table border = "1">';
while($query->have_posts()):
$query->the_post();
if($counter == 6):
$out .= '<tr class = "post_list">';
else:
$counter++;
endif;
$out .= '<td>'.get_the_post_thumbnail(get_the_ID(), array(100,100)).'<br>'.get_the_title().'</td>';
if($counter == 6):
$out .= '</tr>';
$counter = 0;
endif;
endwhile;
$out .= '</table>';
wp_reset_postdata();
else:
$out = 'No Posts Found....';
endif;
wp_reset_query();
return $out;
}
add_action('init', 'spyropress_get_attached_posts');
?>
你這樣做是完全錯誤的。閱讀:http://codex.wordpress.org/AJAX_in_Plugins – RRikesh