カスタムフィールドの「関連」を逆引きする
- 2016.11.08
- CMS Wordpress
- Advanced Custom Fields, 逆引き, 関連
「紐付けられた記事」から「紐付けた記事」を出力する
<?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();?>
-
前の記事
固定ページにカテゴリーを紐付けする 2016.11.08
-
次の記事
WPの記事インポート時にパーミッションの変更を聞かれる場合 2016.11.08