Skip to content

WordPress: display multiple custom fields with the same name.

where ‘reference’ is your multiple custom field with the same name. 

<?php  $reference_urls = get_post_meta( get_the_ID(), 'reference' ); if ( $reference_urls ) : ?>

<h2>Reference</h2>

<?php foreach( $reference_urls as $reference_url ) { ?>

<a href="<?php echo $reference_url; ?>" rel="nofollow"><?php echo $reference_url; ?> </a>

<?php } ?>
         	
<?php endif; ?>