Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i have been working on a custom system for my site where users can have a seperate account, setting and profile page to make my site a bit more interactive and community type. with some other additional stuff. I am new to coding, i have managed to make the profile pages etc.

Right now i am stuck in adding a check box list of tags to user settings page. where a user can select multiple tags as interest.. so i can use those to show him recommended posts randomly on his account page .

i was able to add two extra fields (Twitter/facebook) in the settings page with this code :

function add_bkmrks_contactmethod( $bcontactmethods ) {
$bcontactmethods['Twitter'] = 'Twitter';
$bcontactmethods['Facebook'] = 'Facebook';
return $bcontactmethods;

and tehse can be easily called on pages as well by using $userinfo->Twitter etc. but i have no clue about the checkboxlist... and calling the array etc.

If you guys came across any article or chunk of code which can help me get this resolved i wil be thankful :) cheers Ayaz

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Justin Tadlock has a good tutorial to get you started:


There are some specifics to dealing with checkboxes however, and some custom code if you want to make checkboxes that correspond to tags/categories.

To generate the form fields and save the data use the following snippet:


function user_interests_fields( $user ) {
    // get product categories
    $tags = get_terms('post_tag', array('hide_empty' => false));
    $user_tags = get_the_author_meta( 'user_interests', $user->ID );
    <table class="form-table">
            <th>My interests:</th>
        if ( count( $tags ) ) {
            foreach( $tags as $tag ) { ?>
            <p><label for="user_interests_<?php echo esc_attr( $tag->slug); ?>">
                    id="user_interests_<?php echo esc_attr( $tag->slug); ?>"
                    name="user_interests[<?php echo esc_attr( $tag->term_id ); ?>]"
                    value="<?php echo esc_attr( $tag->term_id ); ?>"
                    <?php if ( in_array( $tag->term_id, $user_tags ) ) echo ' checked="checked"'; ?> />
                <?php echo esc_html($tag->name); ?>
        } ?>
add_action( 'show_user_profile', 'user_interests_fields' );
add_action( 'edit_user_profile', 'user_interests_fields' );

    // store interests
    function user_interests_fields_save( $user_id ) {
        if ( !current_user_can( 'edit_user', $user_id ) )
            return false;
        update_user_meta( $user_id, 'user_interests', $_POST['user_interests'] );
    add_action( 'personal_options_update', 'user_interests_fields_save' );
    add_action( 'edit_user_profile_update', 'user_interests_fields_save' );


You can then call the get_the_author_meta() function to get at your array of tag IDs which can then be used in a query eg:

query_posts( array( 'tag_id' => get_the_author_meta( 'user_interests', $user_id ) ) );
share|improve this answer

What about if you simply want to add a number of checkboxes to a user profile and you want the checkboxes to print something on the front end of your wordpress site.

There should be code that you have to add to create the checkboxes and make them editable under a user profile.

Then a way to see if a checkbox is checked on the front end and print a result.

share|improve this answer
That is what i was looking for actually . –  Ayaz Malik Jan 21 '11 at 23:34
This is not a classic forum, you should not put a followup question as an "answer". You can use the "Ask Question" button above to ask a new question, and then remove this "answer" to keep the site clean. –  Jan Fabry Jan 25 '11 at 9:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.