Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple wordpress custom post meta values
    primarykey
    data
    text
    <p>I'm pretty hopeless at PHP, so I figured I'd ask for a bit of help!</p> <p>I'm using WordPress as a CMS for a music agency site at <a href="http://daviesmusic.com" rel="nofollow">daviesmusic.com</a> and have lots of extra information for the various artists via custom fields. So far, I've just retrieved the custom field values one by one, like so: </p> <pre><code>&lt;?php //audio title $audio_title = get_post_meta($post-&gt;ID, 'audio_name', true); if ($audio_title) : ?&gt; &lt;p&gt;&lt;?php echo $audio_title; ?&gt;&lt;/p&gt; </code></pre> <p>This works fine, only I have lots of custom fields that all require different outputs. I have for instance a photo for the artist, an audio file, the title of the audio file and some notes about the audio file, like so:</p> <pre><code> &lt;?php //profile image $profile_pic = get_post_meta($post-&gt;ID, 'profileimage', true); if($profile_pic) : ?&gt; &lt;img class="post-thumb-single" src="&lt;?php bloginfo('template_directory'); ?&gt;/timthumb.php?src=&lt;?php echo $profile_pic; ?&gt;&amp;a=t&amp;h=278&amp;w=278&amp;zc=1" alt="&lt;?php the_title(); ?&gt;" /&gt; &lt;?php endif; //photographer $photographer = get_post_meta($post-&gt;ID, 'photographer', true); if($photographer) : ?&gt; &lt;p id="photographer"&gt;Photographer: &lt;b&gt;&lt;?php echo $photographer; ?&gt;&lt;/b&gt;&lt;/p&gt; &lt;?php endif; //audio title $audio_title = get_post_meta($post-&gt;ID, 'audio_title', true); if ($audio_title) : ?&gt; &lt;h4 class="nsmb"&gt;Audio files&lt;/h4&gt; &lt;p&gt;&lt;?php echo $audio_title; ?&gt;&lt;/p&gt; &lt;?php //audio file $audio = get_post_meta($post-&gt;ID, 'audiofile', true); if ($audio) : ?&gt; &lt;p class="audio" id="audioplayer_1"&gt;Sorry, there was a problem loading the file.&lt;/p&gt; &lt;script&gt;AudioPlayer.embed("audioplayer_1", {soundFile: "&lt;?php echo $audio; ?&gt;"});&lt;/script&gt; &lt;?php $audio_credits_1 = get_post_meta($post-&gt;ID, 'audio_credits_1', true); if ($audio_credits_1) : ?&gt; &lt;p class="audio_cred"&gt;&lt;?php echo $audio_credits_1; ?&gt;&lt;/p&gt; &lt;?php endif; endif; endif; ?&gt; </code></pre> <p>Lots of code. I'm sure there must be a more efficient way to retrieve the values! Any ideas?!</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload