function checkRelation($id, $direction)
{
if ($direction == "to") {
$connected = new WP_Query([
"relationship" => [
"id" => $id,
"to" => get_the_ID(),
],
"nopaging" => true,
]);
} else {
$connected = new WP_Query([
"relationship" => [
"id" => $id,
"from" => get_the_ID(),
],
"nopaging" => true,
]);
}
$count = $connected->found_posts;
while ($connected->have_posts()):
$connected->the_post(); ?>
<a>"><?php the_title(); ?></a>
<?php
endwhile;
wp_reset_postdata();
return "Connected posts/pages: " . $count;
}