Custom Author Fields + Existing Taxonomy – Integrating the Two Dynamically?

I am trying to integrate both the values from an existing custom taxonomy and custom author profile fields. I would like the values to be used as the options from which an author can select when updating/filling out her profile.

The below works – kind of. (Found in functions.php file)

It saves to the database (users table) but it the “checked” radio does not save. It also does not print properly in the profile section, and looks like this (immediately preceding the radio button) checked="checked" />

… Here is the full code

<tr>
<th><label for="sorority"><?php _e('What sorority are you in?'); ?></label></th>
    <td>
        <?php $sorority = get_the_author_meta( 'sorority', $user->ID ); ?>
        <?php
             $terms = get_terms("sorority");
             $count = count($terms);
             echo '<ul>';
                    foreach ( $terms as $term ) {   
                        echo '<li><input type="radio" value="' . esc_attr( $term->name ) . '" name="sorority" <?php if ($sorority == "' . esc_attr( $term->name ) . '") { ?>checked="checked"<?php }?> />'.$term->name.'</li>';
             }
             echo "</ul>";
            ?>
    </td>
</tr>

Any thoughts? I believe the problem is something with this line:

 <?php if ($sorority == "' . esc_attr( $term->name ) . '") { ?>checked="checked"<?php }?> 

2 Answers
2

Figured it out, for anyone who needs help with this I’m sure you can use with categories/tags as well (can also use with radio inputs and checked=”checked”:

<tr>
 <th><label for="sorority"><?php _e('Sorority is...') ?></label></th>
  <td><?php $sorority = get_the_author_meta( 'sorority', $user->ID ); ?>
    <select name="sorority" id="sorority">
    <?php $terms = get_terms('sorority'); foreach ( $terms as $term ) { ?>
    <option name="sorority" value="<?php echo $term->name; ?>" <?php if ( $sorority == $term->name ) {?> selected="selected" <?php }?>><?php echo $term->name; ?></option>
    <?php } ?>
    </select>
 </td> 
</tr>

Leave a Comment