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.

If I understand correctly, custom fields work like this:

key(string/int) => value(string/int)

Is it possible to define a custom field like this?

key(string/int) => value(array (string/int, string/int))

I want to use such a structure for storing a series of quotations in [quote, source] format, thinking that it would minimize potential input error compared with, say, str_splitting a single value.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Yes you can, either by code:

$demo = array('value1','value2','value3');
update_post_meta($post_id,'meta_key',$demo);

Or simply using the custom fields UI, add ass many values as you want one at a time and make sure they all have the same meta_key.

share|improve this answer
    
If you use the UI and use the same key they get stored seperately though, so wouldn't really address what's being asked. You can of course use arrays on a single entry, you just have to store and retrieve that data yourself - because the WP custom field UI only deals with basic string key => value pairs. –  t31os Aug 17 '11 at 13:51
    
So it is possible, but the UI isn't designed for it. Thanks for your help. I'll look into extending it with a plugin... –  djb Aug 17 '11 at 15:40
    
@t31os: they get stored separately, but if you call them using get_post_meta($post->ID,'meta_key'); you will get an array of values. –  Bainternet Aug 17 '11 at 16:04
    
@bainternet: Yes sure you will, but it stores them seperately, which is not the desired behaviour in relation to this question, or maybe it is and i'm just reading the question differently. ;-) –  t31os Aug 17 '11 at 16:11
    
the question was really about UI, I guess - can I offer the user a custom field called 'quotation' that collects two bits of information, 'quote' and 'source', and have them stored thus: ('quote' => 'veni vidi vici', 'source' => 'julius caesar') –  djb Aug 17 '11 at 16:18
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.