You have to set the relations manually. WordPress is not smart enough to relate to posts by tags if you don’t set them yourself ( It can however use categories, but not really efficient ).
What you can do, is to set some tags on a News
post, and then use them to search the tags in Works
posts. Here is an example:
get_related_posts($id){
// Get current post's tags
$tags = wp_get_post_tags($id);
// Check if the post has any tags
if ($tags) {
// If it does, get them and make a query based on tags
$tag_ids = array();
foreach($tags as $individual_tag) {
$tag_ids[] = $individual_tag->term_id;
}
$args = array(
'tag__in' => $tag_ids,
'post__not_in' => array($id),
'posts_per_page'=>8,
'ignore_sticky_posts'=> 1,
'post_type' => 'works'
);
$related_query = new WP_Query( $args );
// Starting the loop
if ( $related_query->have_posts()) {
while ($related_query->have_posts()){
$related_query->the_post();
the_title();
}
}
}
wp_reset_postdata();
}
Feed this function with a post ID and you will get a list of related posts in the Works
post type that have the same tags as this post:
get_related_posts(get_the_ID());
You can do a conditional to use the same function for both post types.