2013-02-16 49 views

回答

1

如果你想收集結果的數組從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()

+0

它只是打印數組(),它讓我有職位我的wordpress – Ehsan 2013-02-16 14:32:12

+1

嗯...,它適用於我,你在哪裏使用它?我使用get_the_title()中的get_the_ID()更新了代碼。 – birgire 2013-02-16 14:40:18