WordPress.org

Ready to get started?Download WordPress

Forums

get_the_author_meta not calling from within a function (2 posts)

  1. Brendino
    Member
    Posted 4 years ago #

    I've been using functions.php in the Sandbox theme as a place to plug in heaps of custom user meta so that I can make profile pages for each user. A typical field looks like this:

    <tr>
    	<th><label for="hometown">Hometown</label></th>
    		<td>
    		<input type="text" name="hometown" id="hometown" value="<?php echo esc_attr( get_the_author_meta( 'hometown', $user->ID ) ); ?>" class="regular-text" /><br />
    			<span class="description">Where are you from?</span>
    		</td>
    </tr>

    This code works perfectly, but it was repetitious, so I wanted to make a function in PHP to streamline everything. This is the code I came up with:

    function insert_input($input_name,$input_title,$input_desc) {
    echo '<tr><th><label for="' . $input_name . '">'. $input_title . '</label></th><td><input type="text" name="'. $input_name .'" id="'. $input_name .'" value="' . esc_attr( get_the_author_meta( $input_name, $user->ID ) ) . '" class="regular-text" /><br /><span class="description">'. $input_desc .'</span></td></tr>';
    }

    Now, the function works. When this is placed with all the other necessary code, it creates an input, you can type in info, and when you save the changes, it gets stored in the DB. However, when the page reloads, the field is still empty.

    I've narrowed the problem down to get_the_author_meta(). It's not displaying in the function, even though it did before I created a function. What am I missing?

  2. Brendino
    Member
    Posted 4 years ago #

    I also tried the_author_meta() instead of get_the_author_meta() - no dice.

Topic Closed

This topic has been closed to new replies.

About this Topic