對於我的生活,我不明白爲什麼這不起作用。使用數組排除頁面
我試圖讓這個選擇列表顯示除了我想排除的一對夫婦以外的所有頁面。我只是通過標題來獲取頁面,然後從中獲取ID。
<select>
<?php
// Get these pages by their title
$page1 = get_page_by_title('My First Page');
$page2 = get_page_by_title('My Second Page');
// The pages to be excluded
$excludeThese = array(
$page1->ID . ',' .
$page2->ID
);
// Args for WP_Query
$args = array(
'post__not_in' => $excludeThese,
'post_type' => 'page',
'posts_per_page' => -1,
'order' => 'asc'
);
$pages_query = new WP_Query($args);
while ($pages_query->have_posts()) : $pages_query->the_post();?>
<option value="<?php the_permalink(); ?>"><?php the_title(); ?></option>
<?php endwhile; wp_reset_query(); ?>
</select>
如果我回聲$第1頁和第2頁$時,頁面的ID的顯示,所以因此$ excludeThese陣列應該使用它們(是嗎?)。
如果我硬編碼的ID到$ excludeThese陣列,而不是像這樣...
$excludeThese = array(1, 2);
...那麼這一切工作正常。所以看起來$ excludeThese陣列工作不正常。
我很想知道我在這裏做錯了什麼。
乾杯你們都。
'post__not_in'應該是'post_not_in'(POST'後'一個下劃線) – celeriko