I Have A Custom Type Post our-trainers which has a post XYZ and MTJ etc. and another post ABC and TKY etch, XYZ is the Parent of ABC and TKY i want to display only ABC and TKY post
like -
XYZ
ABC (description).
ABC_ (description).
MTJ
child post 1(description).
child post 2(description).
<?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. ?>
shows only last parents post and there child posts.
sYou could try changing your query. In this case adding the query Key: post_parent__in
. This should limit the Results to all our-trainers
Post-Type that have a specific parent ID.
<?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...