2017-04-16 21 views
1

我想要使用wp_get_recent_posts()獲得10個最近的帖子和頁面。我想顯示最近的帖子和特定模板的最近頁面。下面是我的代碼,但我沒有得到任何帖子。使用具有特定頁面模板的wp_get_recent_posts

$lastupdated_args = array(
    'numberposts' => 10, 
    'orderby' => 'post_date', 
    'post_type' => array('page', 'post'), 
    'post_status' => 'publish', 
    'meta_query' => array(
          array(
           'key' => '_wp_page_template', 
           'value' => 'tutorial.php', // template name as stored in the dB 
           ) 
         ), 
    ); 
//Loop to display 10 recently updated posts 
$recent_posts = wp_get_recent_posts($lastupdated_args); 

回答

0

我修改了邏輯一點點。現在,而不是使用template我創建了custom post typepost_type相同的參數。

0

試試這個

$lastupdated_args = array(
'numberposts' => 10, 
'orderby' => 'post_date', 
'post_type' => array('page', 'post'), 
'post_status' => 'publish', 
    'meta_key'='_wp_page_template', 
    'meta_value' ='tutorial.php' 
    ); 
    //Loop to display 10 recently updated posts 
    $recent_posts = wp_get_recent_posts( $lastupdated_args); 
+0

謝謝@Osama,我添加了這段代碼,並且只獲取頁面列表沒有帖子 – aje

+0

'post_type'=> array('post','page'); – Osama

+0

我將序列更改爲「後」,「頁」,但沒有運氣,結果相同。 – aje

相關問題