Title: Add custom field dynamically
Last modified: August 20, 2016

---

# Add custom field dynamically

 *  [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [15 years ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/)
 * Hi,
    i have created my custom meta box and now i want add more field into this
   with jquery.
 * i have created my button for add new row with my duplicated field but i dont 
   know the right way for save this.
 * Anyone know a tutorial or one examples for this?
    Any help is appreciate!
 * Thanks in advance!

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/add-custom-field-dynamically-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add-custom-field-dynamically-1/page/2/?output_format=md)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [15 years ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143515)
 * I don’t think I understand what you are doing. Can you explain more precisely?
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [15 years ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143651)
 * Hi i have made a screenshot for explain my situation.
    [image](http://i51.tinypic.com/34jd2lg.gif)
   With add student button i append with jquery any row in my table, but when i 
   update my post wordpress save only the first student.
 * Thanks!
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [15 years ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143653)
 * OK. What is the code that creates those rows and what is the code you are using
   to insert? Please use the [pastebin](http://pastebin.com/).
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143671)
 * [pastebin](http://pastebin.com/bqJJCtdR)
 * Sorry for bad code, im not a good coder!
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143673)
 * Its hard to say without playing with it but it looks like you are telling the
   script to parse only the first student– `foreach ($this->meta_box_students_fields[
   0] as $field) { // save each option`
 * Why have you restricted that to array index ‘0’ only?
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143674)
 * if i put foreach ($this->meta_box_students_fields[] as $field) { // save each
   option, i have this error
 * Fatal error: Cannot use [] for reading…
 * And if i use foreach ($this->meta_box_students_fields as $field) { // save each
   option, i dont see any changes.
 * Anyway im not able to display any saved data in this table, then i dont know 
   what was saved!
 * I thought i need a loop into my table…
 * Thx again!
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143675)
 * You don’t want `$this->meta_box_students_fields[]`, just `$this->meta_box_students_fields`.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143676)
 * You are saving to the `$wpdb->postmeta` table. Just take a look at the table 
   via PhpMyAdmin. Hopefully you have that available.
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143677)
 * OK.
    How can i display this saved data?
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143678)
 * I meant inside at metabox
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143679)
 * Don’t get ahead of yourself. The first step is getting things to insert into 
   the db correctly.
 * I know you are going to want to display the data in your metabox somewhere but
   its going to be hard to find and debug the problem if you don’t know what, if
   anything, is even in the DB. If you don’t know what is being inserted, when you
   try to display the data and have a problem, you won’t know if the problem is 
   with the insert or with the display code. Therefore, watch the DB using some 
   other tool like PhpMyAdmin so that you know what is going on there.
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143680)
 * well, i see db, wordpress put data into db correctly, but only the first values.
 * If i try to add another values, wordpress save only the first line, then only
   the first student.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143681)
 * Did you make the change I suggested?
 * Put `print_r($this->meta_box_students_fields);` on the line right before `foreach(
   $this->meta_box_students_fields...` and post that for me.
 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143683)
 * if i put this on the line right before foreach ($this->meta_box_students_fields…
   i dont see nothing!
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/#post-2143684)
 * Try `var_dump($this->meta_box_students_fields);` instead.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/add-custom-field-dynamically-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add-custom-field-dynamically-1/page/2/?output_format=md)

The topic ‘Add custom field dynamically’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 16 replies
 * 2 participants
 * Last reply from: [mic3000](https://wordpress.org/support/users/mic3000/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/add-custom-field-dynamically-1/page/2/#post-2143693)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
