カスタムフィールドの「関連」を逆引きする

カスタムフィールドの「関連」を逆引きする

「紐付けられた記事」から「紐付けた記事」を出力する

<?php
  $item_ID = $post->ID;
  $array_ID = strval($item_ID);
  $args = array(
    'post_type' => array('sample'),
    'posts_per_page' => -1,
    'meta_query' => array(
      array(
        'key' => 'post_relation',
        'value' => $array_ID,
        'compare' => 'LIKE'
      )
    )
  );
  $the_query = new WP_Query($args);
?>
<?php if($the_query -> have_posts()): ?>
  <h3><?php echo get_the_title($post->ID); ?>に関する情報</h3>
  <ul>
  <?php while($the_query -> have_posts()): $the_query -> the_post();?>
    <li><a href="<?php echo get_permalink( $num->ID ); ?>"><?php echo get_the_title( $num->ID ); ?></a></li>
  <?php endwhile;?>
  </ul>
<?php endif; ?>
<?php wp_reset_postdata();?>