WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted

Yes you can, either by code:

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

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

Your Answer


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.