Advance Custom Field 関連をクエリで情報を取得する
Advance Custom Fieldの関連で投稿情報を取得するにはクエリでmeta_query()
でカスタムフィールドを指定すると取得できます。
コード
<?php
$args = array(
'post_type' => 'post_related', //カスタム投稿タイプ
'meta_query' => array(
array(
'key' => 'cf_related', //関連のフィールド名
'value' => '"'.get_the_ID().'"',
'compare' => 'LIKE'
)
)
);
$query_project = new WP_Query( $args );
?>
<?php while ($query_project->have_posts()) : $query_project->the_post(); ?>
<h2><?php the_title() ?></h2>
<figure class="image"><?php the_post_thumbnail(); ?></figure>
<a href="<?php the_permalink() ?>">記事リンク</a>
<?php endwhile; ?>