我有一個奇怪的問題。我已將自定義字段添加到用戶配置文件,並使用the_author_meta()
函數顯示字段內容。 Yeasterday一切都很棒。但今天它不起作用。將額外字段添加到WordPress用戶配置文件
自定義字段在用戶配置文件中。當我點擊更新配置文件時 - 字段的內容仍然存在(因此應該保存信息)。但在作者頁上,我有<?php the_author_meta('skills'); ?>
什麼也沒有發生。
我跟着這個教程中,當我創建自己的自定義字段: http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields
而這一次,當我試圖找到我的代碼中的錯誤: http://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/
他們都是相似的。我從昨天開始一直使用頁面模板,所以可能會導致問題。所以我刪除了自昨天以來我添加的所有內容。但沒有任何改變。
這裏是我的代碼:
// CUSTOM FIELD IN USER ADMIN - SAVE
add_action('personal_options_update', 'my_save_extra_profile_fields');
add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
function my_show_extra_profile_fields($user) { ?>
<h3>Skills - Färdigheter</h3>
<table class="form-table">
<tr>
<th><label for="skills">Skills</label></th>
<td>
<textarea type="text" name="skills" rows="4" cols="50" id="skills" class="regular-text"><?php echo esc_attr(get_the_author_meta('skills', $user->ID)); ?></textarea><br>
<span class="description">Please enter your skills.</span>
</td>
</tr>
</table>
<?php }
// CUSTOM FIELD IN USER ADMIN
add_action('show_user_profile', 'my_show_extra_profile_fields');
add_action('edit_user_profile', 'my_show_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_user_meta($user_id, 'skills', $_POST['skills']);
}
我試過你的代碼,它工作正常。你確定你在調用'<?php the_author_meta('skills'); ?> [內循環](https://codex.wordpress.org/The_Loop)? – d79 2015-04-01 02:10:36