I made a simple code to improve the results for WordPress related posts area and it works fine , but because my experience in coding is low , my code is very long and i believe that there is a way to make simple and better
here is the code :-
$cat = get_the_category();
$cat0 = $cat[0];
$cat1 = $cat[1];
$cat2 = $cat[2];
$cat3 = $cat[3];
$cat4 = $cat[4];
$cat5 = $cat[5];
$cat6 = $cat[5];
if ($cat0->cat_ID == 10 || $cat1->cat_ID == 10 || $cat2->cat_ID == 10 || $cat3->cat_ID == 10 || $cat4->cat_ID == 10 || $cat5->cat_ID == 10 || $cat6->cat_ID == 10){
$post = get_the_ID();
$args = array('cat'=>10, 'orderby' => 'date', 'showposts' => $related,'post__not_in' => array($post));
} elseif ($cat0->cat_ID == 12 || $cat1->cat_ID == 12 || $cat2->cat_ID == 12 || $cat3->cat_ID == 12 || $cat4->cat_ID == 12 || $cat5->cat_ID == 12 || $cat6->cat_ID == 12){
$post = get_the_ID();
$args = array('cat'=>12, 'orderby' => 'date', 'showposts' => $related,'post__not_in' => array($post));
} else {
$cat = $cat[0];
$cat = $cat->cat_ID;
$post = get_the_ID();
$args = array('cat'=>$cat, 'orderby' => 'date', 'showposts' => $related,'post__not_in' => array($post));
}
$related = new WP_Query($args);
Also, i tried to use "foreach" function but it always fails in "else" part
Thanks