vendredi 24 juillet 2015

Adding multiple checkboxes to wordpress profile

I'm trying to adding a custom user field in Wordpress with multiple checkboxes.

Here's the code

    //------------ Custom field -------------------------------
    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

    function my_show_extra_profile_fields( $user ) { ?>

    <h3>Extra profile information</h3>
    <table class="form-table"><tr>
        <th><label for="skills">Skills</label></th>
        <td>
        <div class="multi_cat_placeholder_thing" style="width:500px;padding:7px;height:160px;font-size:13px;background:#f2f2f2;overflow:auto;float:left;border-radius:5px;border:1px solid #ccc;background:#fcfcfc;padding:12px;font-size:13px;color:#555;">
            <?php 
        $selected_arr = projectTheme_build_my_cat_arr2($pid);
        echo projectTheme_get_categories_multiple2('project_skill', $selected_arr);
        ?>        
        </div>
        <span class="description">Please select your skills.</span>
        </td>
    </tr></table>
    <?php }


    add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

    function my_save_extra_profile_fields( $user_id ) {

        if ( !current_user_can( 'edit_user', $user_id ) )
            return false;

        /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
        update_usermeta( $user_id, 'skills', $_POST['project_skill_cat_multi'] );
    }

//------------ Custom field -------------------------------

The Php code in the "multi_cat_placeholder_thing" div, just create a list of checkboxes with name "project_skill_cat_multi[]".

I followed a tutorial to add custom fields in wordpress, but with checkboxes seems like it doesn't work. Actually I can't understand if the code can't save the values in the database or if I can't print the array.

Someone knows how to do it?




Aucun commentaire:

Enregistrer un commentaire