I'm stuck with the related posts querying. I need the related posts to be displayed with any depth from the main parent. I have the following structure categories on my website:
- Category level 1
-- Category level 2
--- Category level 3
*---- Post in level 3*
--- Category level 3
*--- Post in level 3*
-- Category level 2
-- Category level 2
When we looking at the *---- Post in level 3*
we must see any post from the *-- Category level 2*
ie all the posts that contain this level including child.
Here is my code:
<div class="related_goods">
<span>Related posts:</span>
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>3,
'orderby'=>title,
'post_parent'=> array(),
'caller_get_posts'=>1);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="block-related-item">
<div class="preview-wrap">
<div class="preview">
<? $thumb_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>
<a href="<?php the_permalink() ?>"><? the_post_thumbnail('category_thumbs'); ?>
</a>
</div>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</div>
</div>
<?php
}
}
wp_reset_query();
}
?>
</div>
How can I modify it to obtain the above effect? Thanks a lot in advance!
post_parent
should be an integer - 0 or 1. Are you sure you're not looking forpost_parent__in
?