WordPress.org

Ready to get started?Download WordPress

Forums

PHP - Array from form - WordPress Metadata (1 post)

  1. Omegakenshin
    Member
    Posted 3 years ago #

    I got a custom post type, with a form for storing some data (name, url) to display in a template.

    What I want to know is how can I store those values in an array?

    An example of my code:

    <? function files_metadata(){
            global $post;
            $custom = get_post_custom($post->ID);
            $name = $custom["name"][0];
            $url = $custom["url"][0];
    
            echo '<input type="hidden" name="files_metadata" id="files_metadata" value="' .wp_create_nonce('files_m'). '" />'; ?>  
    
    <label>Name: </label><br/>
    <input id="name" name="name" value="<?php echo $name; ?>" />
    <label>Url: </label><br/>
    <input id="url" name="url" value="<?php echo $url; ?>" />
    
    <? function save_meta_files($post_id) {
            if (!wp_verify_nonce($_POST['files_metadata'], 'files_m')) return $post_id;
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
    
            update_post_meta($post_id, "name", $_POST["url"]);
            update_post_meta($post_id, "url", $_POST["url"]);
        }  
    
    add_action('save_post', 'save_meta_files'); ?>

    To this I want to add something like...

    $url = $custom["url"][0];
    $url2 = $custom["url"][1];
    $url3 = $custom["url"][2];
    
    <input id="url" name="url[0]" value="<?php echo $url; ?>" />
    <input id="url2" name="url[1]" value="<?php echo $url2; ?>" />
    <input id="url3" name="url[2]" value="<?php echo $url3; ?>" />
    
    update_post_meta($post_id, "url", $_POST["url"][0]);
    update_post_meta($post_id, "url2", $_POST["url"][1]);
    update_post_meta($post_id, "url3", $_POST["url"][2]);

    ...but that actually works...

    I hope you understand me,
    Thanks for your time

Topic Closed

This topic has been closed to new replies.

About this Topic