Home / custom field / How to display multiple custom field values
  • How to How to display multiple custom field values

    how-to-display-multiple-custom-field-values

    Adding this snippet within the loop of your wordpress theme will let you display multiple instances of a custom field value.

    ( example screenshot ) ( click code to copy )

    wordpress snippet : PHP

    <>
    <?php
    $press_quotes = get_post_meta($post->ID, "pressquote", false);
    if ($press_quotes[0]=="") { ?>
    <!-- If there are no custom fields, show nothing -->
    <?php } else { ?>
    <div>
    	<h3>From the Press</h3>
    	<?php foreach($press_quotes as $press_quotes) {
    	echo '<blockquote><p>'.$press_quotes.'</p></blockquote>';
    	} ?>
    </div>
    <?php } ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_post, get_post_meta, wp,