Support » Plugins » get_the_author_meta not calling from within a function

  • 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:

    	<th><label for="hometown">Hometown</label></th>
    		<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>

    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?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘get_the_author_meta not calling from within a function’ is closed to new replies.