例えば、post_typeが「hoge1」と「hoge2」の投稿も含めたい場合。
まず、wordpress-popular-posts.phpの510行目(ver. 2.2.1)
$nopages = "AND $wpdb->posts.post_type = 'post'";
を
$nopages = "AND $wpdb->posts.post_type IN ('post', 'hoge1', 'hoge2')";
とする。
これで「hoge1」と「hoge2」も対象に含まれるようになる。
次に、wpp_get_mostpopular()で吐き出されるものでは柔軟にいじれないので、ob_start()で投稿IDだけ抜き出し、投稿IDの配列を生成する。
if ( function_exists( 'wpp_get_mostpopular' ) ) {
$args = array (
'order_by' => 'views',// views=閲覧数, comments=コメント数
'range' => 'all',// dialy=日間, weekly=週間, monthly=月間, all=総数
'stats_comments' => 0,// コメント数表示
'limit' => 10,
);
ob_start ();
wpp_get_mostpopular( http_build_query ( $args ) );
$output = ob_get_contents ();
ob_end_clean ();
preg_match_all ( '/([0-9]+)\.html/', $output, $result );
$p_arr = $result[1];
if ( count ( $p_arr ) > 0 ) {
$args = array (
'post_type' => array ( 'hoge1', 'hoge2' ),
'post__in' => $p_arr,
);
query_posts( $args );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
}
wp_reset_query();
}
}
} 