Grow your CSS skills. Land your dream job.

Completely stumped on saving WordPress custom field data

  • # September 13, 2012 at 5:03 pm

    I am trying to run a query to load a checkbox and dropdown where the user can select who else was involved on a project, but I cannot figure out how to save this data since each checkbox/dropdown would be unique, any ideas?


    // Staff Dropdown
    add_action('add_meta_boxes', 'jpg_affiliated');
    function jpg_affiliated()
    {
    add_meta_box('jpg_affiliated_staff', 'Who Was Involved?', 'jpg_affiliated_staff_callback', 'post', 'normal', 'default');
    }
    function jpg_affiliated_staff_callback($post)
    {
    $values = get_post_custom($post->ID);
    wp_nonce_field('jpg_affiliated_nonce', 'jpg_affiliated_nonce_field');
    ?>

    Select any staff that were involved in this event and what their role was.


    < ?php
    $team = new WP_Query(array('post_type' => 'jpg_profiles','post_status' => 'publish','posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC'));
    while($team->have_posts()) : $team->the_post();
    ?>











    < ?php
    endwhile;
    wp_reset_postdata();
    }

    add_action('save_post', 'jpg_save_associated');
    function jpg_save_associated($post_id)
    {
    // Bail if we're doing an auto save
    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;

    // if our nonce isn't there, or we can't verify it, bail
    if(!isset($_POST) || !wp_verify_nonce($_POST, 'jpg_affiliated_nonce' )) return;

    // if our current user can't edit this post, bail
    if(!current_user_can('edit_post')) return;

    // Probably a good idea to make sure your data is set
    if(isset($_POST)){update_post_meta($post_id, 'jpg_test', esc_attr($_POST));}
    }
    ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".