0
我想有一個WP_Query的輸出到array.for例如我最後的10后冠軍數組或最後發表的帖子的網址WordPress的查詢帖子然後放入陣列
我想有一個WP_Query的輸出到array.for例如我最後的10后冠軍數組或最後發表的帖子的網址WordPress的查詢帖子然後放入陣列
如果你想收集結果的數組從WP_Query()
到另一個數組,你可以試試這個:
$my_array=array();
// the query
$args=array('post_type' => 'post','posts_per_page'=>10,'orderby'=>'date', 'order'=>'ASC');
$my_query = new WP_Query($args);
if ($my_query->have_posts()) :
while ($my_query->have_posts()) : $my_query->the_post();
$my_array[]=get_the_title(get_the_ID());
endwhile;
endif;
// debug:
print_r($my_array);
print_r($my_query);
而這個例子給你10個最後一篇標題爲陣列$my_array()
它只是打印數組(),它讓我有職位我的wordpress – Ehsan 2013-02-16 14:32:12
嗯...,它適用於我,你在哪裏使用它?我使用get_the_title()中的get_the_ID()更新了代碼。 – birgire 2013-02-16 14:40:18