2016-11-19 1 views
1

特定のテンプレートを使用しないすべてのWordPressの子ページIDの配列を取得できますか?特定のテンプレートを使用していない子ページIDを一覧表示する

私は私がしてテンプレートを得ることができます知っている:

'meta_key' => '_wp_page_template', 
'meta_value' => 'template.php' 

と私は私が一緒にクエリを置くことができるかどうかはわかりget_pagesを使用しますが、ことができませんでした期待しています。

+0

テンプレートを制限したいですか? –

+0

これを管理ダッシュボードで探してみましたか? – elicohenator

+0

最終的には、特定のテンプレートを使用していないすべての子ページのリストを表示することになりますが、その時点でIDのリストを取得したいだけです。 –

答えて

0

これは機能しますが、より良い方法がありますか?

$args = array(
    'post_parent' => $parent_ID, 
    'post_type' => 'page', 
    'numberposts' => -1, 
    'post_status' => 'publish' 
); 
$children = get_children($args); 
$exclude_children = null; 
foreach($children as $child) { 
    $metadata = get_post_meta($child->ID); 
    if($metadata['_wp_page_template'][0] == 'template.php') { 
     $args = array(
      'post_parent' => $child->ID, 
      'post_type' => 'page', 
      'numberposts' => -1, 
      'post_status' => 'publish' 
     ); 
     $exclude_array = get_children($args); 
     foreach($exclude_array as $exclude) { 
      $exclude_children .= $exclude->ID.','; 
     } 
    } 
} 
関連する問題