Title: Popular Postsをquery_postsで取得
Last modified: 2018年9月9日

---

# Popular Postsをquery_postsで取得

 *  [mentos2020](https://ja.wordpress.org/support/users/mentos2020/)
 * (@mentos2020)
 * [8年、 2ヶ月前](https://ja.wordpress.org/support/topic/popular-posts%e3%82%92query_posts%e3%81%a7%e5%8f%96%e5%be%97/)
 * wordpressのPopular Postsをquery_postsで取得する記事をみつけたのでんですが少々
   困っています。
    functions.phpに追加
 *     ```
       //popular post からquery_posts生成
       function get_popular_args($range= "weekly", $limit = 8){
         //urlを作成
         $shortcode = '[wpp';
         $atts = '
                 post_html="{url},"           
                 wpp_start=""
                 wpp_end=""
                 order_by="views"
                 post_type="post"
                 stats_comments=0
                 stats_views=1
                   ';
         $atts_2 = ' range='. $range;
         $atts_3 = ' limit='. $limit;
         $shortcode .= ' ' . $atts . $atts_2 . $atts_3 . ']';
         $result = explode(",", strip_tags(do_shortcode( $shortcode )));
         $ranked_post_ids = array();
   
         //urlから投稿IDを作成
         foreach($result as $_url){        
           if(!empty($_url) && trim($_url) != ''){
             $id_string = url_to_postid($_url);
             array_push ($ranked_post_ids, intval($id_string));
           }
         }
   
         //idをreturn
         $args = array(
           'posts_per_page' => 20,
           'post__in' => $ranked_post_ids,
           'orderby' => 'post__in'
         );
   
         return $args;
       }
       ```
   
 * 表示場所に下記を記入　月間人気記事を10件取得
 *     ```
       <?php $args = get_popular_args('monthly', '10');
       query_posts($args); ?>
       ```
   
 * サイドバーに表示させるには問題は無いのですが固定ページで全ての投稿のランキング
   を表示させる
    場合、全ての投稿が一括で表示されてしまいページネーションが使えま
   せん。
 * 「100件中 1位 ～ 10位 まで表示」され、ページ送り以降は「11位 ～ 20位」と成る様
   にするには
    どうすれば良いのでしょうか？
 * ヘルプの必要なページ: _[リンクを見るには[ログイン](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fja.wordpress.org%2Fsupport%2Ftopic%2Fpopular-posts%25E3%2582%2592query_posts%25E3%2581%25A7%25E5%258F%2596%25E5%25BE%2597%2F%3Foutput_format%3Dmd&locale=ja)]_

1件の返信を表示中 - 1 - 1件目 (全1件中)

 *  [munyagu](https://ja.wordpress.org/support/users/munyagu/)
 * (@munyagu)
 * [8年、 2ヶ月前](https://ja.wordpress.org/support/topic/popular-posts%e3%82%92query_posts%e3%81%a7%e5%8f%96%e5%be%97/#post-230082)
 * こんにちは
 * APIに start_with といったような取得開始位置を指定するパラメータが無いので、通常
   の方法では無理そうです。
 * [https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages](https://github.com/cabrerahector/wordpress-popular-posts/wiki/1.-Using-WPP-on-posts-&-pages)
 * Popular Postsがどの様にデータを保持しているのか、どう取得しているのかを調べれ
   ばできるかもしれませんが・・・

1件の返信を表示中 - 1 - 1件目 (全1件中)

 トピック「Popular Postsをquery_postsで取得」には新たに返信することはできません。

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1件の返信
 * 2人の参加者
 * 最後の返信者: [munyagu](https://ja.wordpress.org/support/users/munyagu/)
 * 最後の活動: [8年、 2ヶ月前](https://ja.wordpress.org/support/topic/popular-posts%e3%82%92query_posts%e3%81%a7%e5%8f%96%e5%be%97/#post-230082)
 * 状態: 未解決

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
