MENU

別のカスタム投稿タイプの一覧を特定のkeyで取得

<div class="swell-block-capbox cap_box">
<div class="cap_box_ttl"><span>RACE RECORD 競走成績</span></div>
<div class="cap_box_content"><!-- wp:html -->
<dl class="race-record-scr">

<ul class="e_list01">
<?php $c_value = get_post_meta($post->ID, 'horse-name', true); ?>

<?php 
$args = array(
'post_type' => array('race-record'), //一覧表示したいカスタム投稿タイプのスラッグを入れます。
'showposts' => 10,
'meta_query' => array(
	array(
'key' => 'horse-name', //変数$c_valueに入れたカスタムフィールドの値と一致するカスタムフィールドを入れます。
'value' => $c_value ,
'compare'=>'LIKE'))
		);

$my_query = new WP_Query($args);
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); //一致するカスタム投稿がある場合にループ開始。下記のリストが表示されます。
?>

<dl class="archive-race-record">

<p class="archive-race-record-date"><?php the_field('date'); ?></p>
<table>
<tbody>
<tr>
<th>馬名</th>
<th>開催</th>
<th>R</th>
<th>レース名</th>
<th>コース・距離</th>
<th>騎手</th><
th>厩舎</th>
<th>着順</th>
<th>タイム</th>
</tr>
<tr>
<td><?php the_field('horse-name'); ?></td>
<td><?php the_field('place'); ?></td>
<td><?php the_field('round'); ?></td>
<td><?php the_field('race-name'); ?></td>
<td><?php the_field('course-distance'); ?></td>
<td><?php the_field('jockey'); ?></td>
<td><?php the_field('stable'); ?></td>
<?php if(get_post_meta($post->ID,'rank',true) == '1着'): ?>
<td class="no1"><?php the_field('rank'); ?></td>
<?php else:?>
<td><?php the_field('rank'); ?></td>
<?php endif; ?>

<td><?php the_field('time'); ?></td>
</tr>
</tbody>
</table>

</dl>
<?php endwhile; endif; wp_reset_postdata(); ?>
</ul>
</dl>
<!-- /wp:html --></div>
</div>
目次