:
ID;
$ids=array($postid);
$tags=get_the_tags( $postid );
$categories = get_the_category( $postid );
$post_cnt=0;
$first=0;
if ($tags) {
$tags_ids = array();
foreach($tags as $tag) $tags_ids[] = $tag->term_id;
$args=array(
'tag__in' => $tags_ids,
'post__not_in' => $ids,
'showposts'=>$postsCnt,
'ignore_sticky_posts'=>true);
$posts=get_posts($args);
if( count($posts)>0 ) {
foreach ($posts as $p) {
$post_cnt++;
$ids[]=$p->ID;
}
}
}
if ($categories&&($post_cnt<$postsCnt)) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => $ids,
'showposts'=>$postsCnt-$post_cnt,
'ignore_sticky_posts'=>true);
$posts=get_posts($args);
if( count($posts)>0 ) {
foreach ($posts as $p) {
$post_cnt++;
$ids[]=$p->ID;
}
}
}
if (!$post_cnt) {
?> $ids, 'posts_per_page' => $postsCnt );
$items = new WP_Query( $args );
while ( $items->have_posts() ) : $items->the_post();
?>