Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created a custom field named 'Essential Info', which I plan to allow the admin to add a list of values to. E.g.

No Pets On-site doctor Car Parking 100m from beach

...etc.

However, I'm not entirely sure how I can achieve this with custom fields. I was hoping that I could somehow allow the user to separate these values with a comma, and in the template tell it to output a separate list item everytime a value is separated by a comma.

At the moment, this is my code which obviously outputs whatever is in the custom field, but I need the admin to be able to add a list of values rather than a single line value:

<ul>
            <li><span>
            <?php if ( function_exists('get_custom_field_value') ){
                    get_custom_field_value('Essentials', true);
            } ?>
            </span></li>
        </ul>

Thanks

share|improve this question
add comment

1 Answer

foreach($items as $item) { 

$item = nl2br($item);
list($name,$src,$price,$desc) = explode('<br />',$item); 

echo "<div class=\"item\">";
echo "<h2>$name</h2>";
echo "<img src=\"".trim($src)."\" />";
echo "<br />Price: $price";
echo "<br />Description: $desc";
echo "</div><br />"; 

}

This works if you have them hit enter after each value to make the list. http://vudu.me/f7 Is an article I wrote, and it has a link to my source, so you can get a better understanding of it

This would work best... I think... if you know how many values would be entered? You still need to open up by actually using get_post_meta of course....

share|improve this answer
    
I'm not sure if this actually solves the problem. The thing is, I only have one custom field, called Essentials, and the admin will be inputing a number of different fields separated by commas, or just by pressing ENTER as you suggested, but by the looks of your code, you already have a number of different variables set, and are simply adding a break-space between each one right? Apologies if I have misunderstood, as I'm not entirely familiar with PHP in Wordpress. I'm just a bit unsure how to apply what you have answered to my situation –  remi90 Sep 16 '11 at 14:06
    
well, what it does it take the values, and assign them in order to the variables in the list. 1st line goes to $name, 2nd line goes to $src, etc. Then we use those variables below. It would work best if you knew the max number of values which may be entered so you could use a variable for each... if you don't, I'm not sure exactly how to modify what I have above to allow for unlimited entries. That code doesn't add a break space, it breaks apart the list on a break space. It looks for a return –  Rev. Voodoo Sep 16 '11 at 19:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.