• WordPress 1.2, I’m trying to figure out how to make it so that the add_meta function could handle and insert multiple meta data fields at once. I’m hacking my post form so that each meta data category can be filled in on the same form, instead of having to click “Save and Continue Editting” each time (I have lots of metadata fields to add per post). Any ideas?

    Could I just pass multiple metakeyinput/metavalue pairs, make an array, and then do a foreach loop with the insert?

    I’ve made my forms into metakeyinput[] ‘s, so they turn into array variables, and I’m using this:

    $metakeyselect = $_POST[‘metakeyselect’] ;
    $metakeyinput = $_POST[‘metakeyinput’] ;
    $metavalue = $_POST[‘metavalue’] ;

    and then:

    $x = count($metavalue);
    $i = 0;

    while ($i < $x)

    {
    $metavalued = $metavalue[$i];
    $metakey = $metakeyinput[$i]; // default

    $result = $wpdb->query(“
    INSERT INTO $tablepostmeta
    (post_id,meta_key,meta_value)
    VALUES (‘$post_ID’,’$metakey’,’$metavalued’)
    “);
    $i++;
    }

    This works, but then it starts to make the delete/update functions funky, and won’t work so well if not all of the fields are filled in every time you save the data.

    There’s got to be an easier way to do this–any ideas, or anyone tried this before?

    thanks!

  • The topic ‘Submit Multiple New Meta Data At Once?’ is closed to new replies.