2016-09-12 6 views
0

に子ポストを表示するなど、ポストXYZMTJを持っているし、別のポストABCTKYエッチング、XYZがされABCTKYの親は私だけABCTKYポストを表示したい</strong>私たちのトレーナー<strong>私はカスタム・タイプのポストを持っているWordpressのページテンプレート

様 -

XYZ

ABC(説明)。

ABC_(説明)。

MTJ

子ポスト1(説明)。

子供ポスト2(説明)。

<?php 
/** 
    * Template Name: Blog 

    The template for displaying all pages. 
    * 
    * This is the template that displays all pages by default. 
    * Please note that this is the WordPress construct of pages 
    * and that other 'pages' on your WordPress site will use a 
    * different template. 
    * 
    * @package Sydney 
    */ 

    get_header(); 
?> 

<?php 
       $array = array('post_type'=>'our-trainers', 'posts_per_page' => 30, 'order' => 'ASC'); 
       $array_query = new wp_query($array); 
      while ($array_query->have_posts()) : $array_query->the_post(); 
      ?> 
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
       <?php //the_excerpt(); ?> 
     <?php 
      $array = array('post_type'=>'our-trainers', 'post_parent' => $post->ID, 'posts_per_page' => 30, 'order' => 'ASC'); 
      $array_query = new wp_query($array); 
     while ($array_query->have_posts()) : $array_query->the_post(); 
     ?> 
      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
      <?php the_excerpt(); ?> 


    <?php endwhile; // end of the loop. ?> 

     <?php endwhile; // end of the loop. ?> 

は、最後の親の投稿と子供の投稿のみを表示します。

答えて

0

■クエリを変更できます。この場合、クエリキー:post_parent__inを追加します。結果は特定の親IDを持つすべてour-trainersポストタイプに限定されます。

<?php 
      $array = array(
       'post_type'  => 'our-trainers', 

       // ADD THE FOLLOWING LIKE: THE ARRAY COULD BE A LIST OF IDS OR JUST 1 ID. 
       'post_parent__in' => array("ID_OF_THE_POST_PARENT"), 

       'posts_per_page' => 30, 
       'order'   => 'ASC' 
     ); 
      $array_query = new wp_query($array); 
     while ($array_query->have_posts()) : $array_query->the_post(); 
      // THE REST OF THE CODE... 

OPTION NR 2

<?php 
      $parentIDs = array(214, 412); 
      $array  = array(
       'post_type'  => 'our-trainers', 
       'posts_per_page' => 30, 
       'order'   => 'ASC' 
     ); 
      $array_query = new wp_query($array); 
     while ($array_query->have_posts()) : $array_query->the_post(); 
      $pID   = get_the_ID(); 
      // GET THE POST OBJECT; 
      $pOBJ  = get_post($pID); 
      // CHECK IF THE PARENT ID OF THE POST IS CONTAINED IN THE LIST OF 
      // PARENT_IDS... 
      if(in_array($pOBJ->parent_id, $parentIDs)){ 
       // DISPLAY ONLY THESE POSTS... 
      } 
      // THE REST OF THE CODE... 
+0

感謝。親の投稿は動的でなければならないことを意味します。 – devendra

+0

@devendraこの場合、ループ内でチェックする必要があります。それはそれを行う別の方法です.... – Poiz

関連する問題

 関連する問題