get_the_term_list()
returns HTML but you are trying to use it as if it returned a term ID — 'blog_cats' => $blogcats,
. That is not going to work. You will need to use get_the_terms()
and a tax_query
(I think. I am not 100% sure).
Something like:
$blogcats = get_the_terms($post->ID,'category');
// var_dump($blogcats);
$blogcats = wp_list_pluck($blogcats,'term_id');
// var_dump($blogcats);
$related = get_posts(
array(
'post_per_page' => 5,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $blogcats,
)
),
'post_type' => $posttypenews,
'post__not_in' => array($post->ID)
)
);