2016-09-12 24 views
0

我有一個自定義類型發表我們的教員具有後XYZMTJ等,以及另一篇文章ABCTKY蝕刻,XYZABCTKY的家長,我想只顯示ABCTKY顯示孩子後到WordPress頁面模板

像 -

XYZ

ABC(介紹)。

ABC_(description)。

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

s您可以嘗試更改您的查詢。在這種情況下添加查詢鍵:post_parent__in。這應該將結果限制爲具有特定父ID的所有our-trainers Post-Type。

<?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

相關問題