カスタムフィールドのセットを備えたワードプレスのテーマがあります。これらのうちの 1 つは「作成者」という名前です。
single.php には、同じカスタム フィールド値を持つ他の投稿を表示する div があります。
同じカスタム フィールド値を持つ他の投稿が存在する場合にのみ、この div を表示したいと思います。それ以外の場合は、何も表示したくありません。
ご協力いただきありがとうございます!!
これは私の実際のコードです:
<?php
$myquery = array(
'meta_key' => 'autore',
'meta_value' => $autore,
'showposts' => 2,
'post__not_in' => array($post->ID)
);
if ( $myquery->have_posts() ) : ?>
<div class="related">
<h3>Altre di <?php the_field('autore'); ?></h3>
<ul>
<?php while ( $your_query->have_posts() ) : $your_query->the_post(); ?>
<?php
echo '<li>'; ?>
<?php
$fotorel = get_field('foto_homepage');
list($width, $height) = getimagesize("$fotorel");
$relheight = $height / 2;
?>
<div class="related-foto" style="background:url(<?php the_field('foto_homepage'); ?>) no-repeat center center; height:<?php echo $relheight.'px' ?>"></div>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php echo '</li>';?>
<?php endwhile; ?>
<?php else : // What to do if there are no posts from that author
endif;?>
</ul>
</div>
<?php wp_reset_query(); ?>