Before I created meta-boxes I did things the old fashion way by entering custom fields directly. I went through the process of filling in the ID and the Value by hand and hitting the "update button". I would input whatever I wanted, spaces and . (periods) and they would be correctly applied in my database (ERROR FREE). However I no longer want to do this manually which is why I have created meta-boxes, but since I began using them, special characters like . and spaces wont take, resulting in a blank field when I attempt to update the post in order to save the meta-box values. What am I missing and why do the rules for special characters differ when you manually enter the ID as opposed to having it preset through meta-boxes. Ultimately how can I create meta-box array ID's with special characters?

Note: All my non-special character meta-boxes function properly. So the problem is NOT in the functionality of the code


I am using the mp3 player plugin "mp3-jplayer" which uses custom fields to display audio. The custom field format (which the creator of this plugin determined and I cannot change myself) is...

ID = TrackNumber mp3.Artist

(note the space and the period above, this is what trips up the submission of the metabox value)

Value = SongTitle@SongURL

enter image description here

At the moment I am using meta-boxes to input custom fields as follows:

$meta_boxes[] = array(
'id' => 'musicboxes',
'title' => 'Music Box Head',
'pages' => array('post'),
'context' => 'normal',
'priority' => 'low',

'fields' => array(
        'name' => 'Musicbox 1',
        'desc' => 'ID',
        'id' => '1 mp3.Artist',
        'type' => 'text',
        'std' => '',

However, when I input in the array ID field "1 mp3.Artist" the custom field does not update correctly (in other words, remains blank) and I'm thinking it's because there is a space between the number and the word "mp3". So how would I (if its possible) still be able to keep the space so that the custom field functions properly with the mp3-jplayer plugin.

  • that could be the main reason since spaces and periods are not valid in the name attribute of an input tax, mainly because of the GET restrictions.
    – Bainternet
    Nov 16, 2011 at 10:29
  • Any creative way around this? Would I be better off changing the template for the plugin so that the space and period aren't needed? Nov 16, 2011 at 10:58
  • Any progress? Was one of the answers helpful?
    – fuxia
    Oct 6, 2012 at 22:26

3 Answers 3


You may have build your meta box wrong: If your custom field names are not valid variable names PHP will convert all characters not matching [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff] to underscores. The reason: register_globals. A request field must be able to work as a variable.

There are two workarounds:

  1. Name the field like an array: <input name="foo[TrackNumber mp3.Artist]">. Then just parse foo to get the value. That's what WordPress does with the custom field box.

  2. Search for TrackNumber_mp3_Artist and convert the value before you save it to the database.


Have you tried escaping the text before it's saved to the database?


$mp3ID = esc_textarea($_REQUEST['_mp3IDBoxData']);
update_post_meta(esc_attr($post_id), '_mp3IDBoxData', $mp3ID);

In case you are still looking for an answer; I think you will have to get your hands dirty on this. First off, you need to trim the value that gets registered in the Name custom-field ("1 mp3.Artist").

For example: $id = trim($field['id']); $newID = get_post_meta($post->ID, $id, true);

Hope that helps. I haven't tested it, but the logic behind it should do the trick. Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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