カレンダー
2010年9月
« 7月    
 12345
6789101112
13141516171819
20212223242526
27282930  
カテゴリー
アーカイブ

Posts Tagged ‘バグ’

wp_list_pages関数exclude_treeの複数指定

wp_list_pagesの引数でexclude_treeというバラメータがある。

これを指定すると、そのページIDを親とする子ページもすべて除外してくれる。

カンマで複数指定可能とwordpress.日本語のドキュメントなどでは書かれているのだが、
複数指定をしても、最初に指定したIDしか適用されなかった。

指定の仕方が悪いのか?と色々試したが適用されず・・・。

仕方が無いので中身を見てみた。

wp-admin/post.phpの2603行目あたり

wp-include/post.phpの
function &get_pages($args = ”)
関数内(Ver3.0の場合 3197行あたり)

$exclude = (int) $exclude_tree;
$children = get_page_children($exclude, $pages);
$excludes = array();
foreach ( $children as $child )
    $excludes[] = $child->ID;
$excludes[] = $exclude;
$num_pages = count($pages);
for ( $i = 0; $i < $num_pages; $i++ ) {
    if ( in_array($pages[$i]->ID, $excludes) )
        unset($pages[$i]);
}


 

・・・文字列をそのままintにキャストしてるじゃんorz
それじゃ、カンマ区切りで渡してもキャストしたら最初の値のみになるわな^^;
って、事で以下のように修正(ホントは本体なので修正したくないのだが・・・)

$excludelist = preg_split('/[\s,]+/',$exclude_tree);
if ( count($excludelist) ) {
    $excludes = array();
    foreach ( $excludelist  as $excludestr ) {
        $exclude = intval($excludestr);
        $children = get_page_children($exclude, $pages);
        foreach ( $children as $child )  {
            $excludes[] = $child->ID;
        }
        $excludes[] = $exclude;
    }
    $num_pages = count($pages);
    for ( $i = 0; $i < $num_pages; $i++ ) {
        if ( in_array($pages[$i]->ID, $excludes)  )
            unset($pages[$i]);
    }
}


 

これで複数指定できるようになった♪

2010/7/5 追記
WordPress3.0jaでも上記は未修正でした。。。
あと一部に記載ミスがあったので修正しました(赤字部分)