我將一個WP_Query
對象傳遞給JavaScript文件中的成功函數,並且在試圖循環它時遇到問題。如何通過使用jQuery的WordPress WP_Query對象循環?
我的PHP:
$args = array(
'post_type' => 'post'
);
$query = new WP_Query($args);
// Pass the $query object to the success function in my script.
echo json_encode($query);
在我的劇本我的成功函數:
success: function(data) {
// I'd like to loop through the query object here.
},...
我知道如何通過WP_Query對象服務器端循環:
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
echo get_the_title();
}
}
但如何我可以在我的腳本中使用jQuery成功函數中循環查詢對象嗎?
感謝您的想法,我會試試看... – henrywright 2014-09-05 17:50:24
無後顧之憂。讓我知道你是怎麼辦的。 – ornous 2014-09-05 17:51:04