• Resolved Rose

    (@eos-rose)


    I’m trying to modify my posts by inserting metadata from my custom fields into my posts template. I’ve got everything working, but I’m having trouble figuring out how to separate multiple values with a comma WITHOUT the last value also having a comma after it. My code looks like something like this:

    <?php $keys = get_post_meta($post->ID, 'keys', false); ?>
    			<b>Key:</b> 	<?php foreach($keys as $key) {
    			echo ''.$key.', ';
    			} ?>

    The output looks something like:
    Key: value #1, value #2, value #3,
    and I want to remove the “, ” after value #3…..

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this will work:

    <?php $keys = get_post_meta($post->ID, 'keys', false); ?>
    <b>Key:</b> 	<?php echo implode($keys,', '); ?>
    Thread Starter Rose

    (@eos-rose)

    Awesome! I knew there must be an easy way to do this. <3

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Seperate multiple values in get_post_meta with commas…’ is closed to new replies.