• 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)
  • I don’t think I understand what you are doing. Can you explain more precisely?

    Thread Starter mic3000

    (@mic3000)

    Hi i have made a screenshot for explain my situation.
    image
    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!

    OK. What is the code that creates those rows and what is the code you are using to insert? Please use the pastebin.

    Thread Starter mic3000

    (@mic3000)

    pastebin

    Sorry for bad code, im not a good coder!

    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

    (@mic3000)

    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!

    You don’t want $this->meta_box_students_fields[], just $this->meta_box_students_fields.

    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

    (@mic3000)

    OK.
    How can i display this saved data?

    Thread Starter mic3000

    (@mic3000)

    I meant inside at metabox

    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

    (@mic3000)

    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.

    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

    (@mic3000)

    if i put this on the line right before foreach ($this->meta_box_students_fields…i dont see nothing!

    Try var_dump($this->meta_box_students_fields); instead.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Add custom field dynamically’ is closed to new replies.