2017-05-08 3 views
0

私のプラグインの開発中にこの問題が発生しました。 私はウェブサイトのすべてのページをループし、タイトルとIDを印刷します。 私は単純なループを行うだけで何も印刷されません。wordpressのプラグインのオプションページ内でループを実行することはできますか?

私のプラグインのオプションの中にループをする方法はありますか?

+0

これまでに試したコードのように、詳細を投稿してください。 – Ashkar

+1

これを試しましたか? <?php $ pages = get_pages(); foreach($ページとしての$ページ){ $ page_title = $ page-> post_title; $ page_id = $ page-> ID; } ?> – Ashkar

+0

@Ashkarうん、私はそのコードを試みた。それは動作しますが、私がやったことはしません。これはページでのみ有効です。カスタムポストタイプごとに何かが必要です。これは私が試した単純なループです。<?php if(have_posts()):while(have_posts()):the_post(); the_title(); endwhile; endif; ?> – Gianno

答えて

0

解決策が見つかりました。

プラグインのオプションページ内のブロックのいくつかの種類があるかどうかはわからないが、我々は、コードの小さな部分を持つすべてのカスタムポストタイプでループをすることができます:ここで

<?php 

    //Search only for custom post type which is public. 
    $args = array('public'=>true); 

    //Get all custom post type name 
    $allMyCustomPostTypes = get_post_types($args); 

    foreach ($allMyCustomPostTypes as $myCustomPostType) { 

     //Create a filter for get_posts with every custom post type 
     $filter = array('numberposts' => 5, 'post_type' => $myCustomPostType); 

     //Pass the value to *get_posts* 
     $theposts = get_posts($filter); 

     foreach ($theposts as $thepost) { 

      //Easy print the name of the current post of the current custom post type 
      echo $thepost->post_title; 

     }; 

    }; 

?> 

私たちは、あるこれが役に立てば幸い誰か。

関連する問題