我有一個問題,即將自定義字段添加到wordpress用戶配置文件中,並且輸入的字段顯示在網站的正面。使用下面的教程,我認爲我有它的工作,然而注意到,實際上它只適用於一個用戶,然後所有其他人不工作,這是什麼讓我感到困惑,因爲我習慣於工作或不工作的事情,而這適用於我嘗試過的第一個用戶,但沒有其他用戶。Wordpress問題添加額外的用戶配置文件字段
我看着高低嘗試不同的事情無濟於事。
我的目的是允許多個wordpress用戶將他們的Google+個人資料添加到具有rel屬性的特定作者的帖子上的wordpress頭部。
這裏是我曾經用過
http://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/
這裏的教程是我使用的功能
1中的代碼 - 這增加了該領域的用戶配置文件
/* Add Additional Fields to Author Profile */
add_action('show_user_profile', 'my_show_extra_profile_fields');
add_action('edit_user_profile', 'my_show_extra_profile_fields');
function my_show_extra_profile_fields($user) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="u-profs">Profile Info</label></th>
<td>
<input type="text" name="u-profs" id="u-profs" value="<?php echo esc_attr(get_the_author_meta('u-profs', $user->ID)); ?>" class="regular-text" /><br />
<span class="description">Enter Your Profile Info.</span>
</td>
<td>
<input type="text" name="u-profs2" id="u-profs2" value="<?php echo esc_attr(get_the_author_meta('u-profs2', $user->ID)); ?>" class="regular-text" /><br />
<span class="description">Enter Your Google+ Url.</span>
</td>
</tr>
</table>
<?php }
add_action('personal_options_update', 'my_save_extra_profile_fields');
add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
foreach($user_ids as $user_id){
update_user_meta($user_id, 'u-profs2', $_POST['u-profs2']);
}
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 'u-profs' to the field ID. */
update_user_meta($user_id, 'u-profs', $_POST['u-profs']);
update_user_meta($user_id, 'u-profs2', $_POST['u-profs2']);
}
2 - 獲取字段內容並將其添加到wordpress的wp_head
/* Google Rel Author */
function google_rel_author_in_document_head() {
echo '<link rel="author" href="' . get_the_author_meta('u-profs2') . '"/>';
}
add_action('wp_head', 'google_rel_author_in_document_head',99);
StackOverflow上這個鏈接似乎是一個類似的問題,但沒有得到解決......
Multiple update_user_meta in Wordpress
在哪文件把這個代碼...即時新的wordpress ... – harsh4u 2013-04-20 19:12:24
你知道如何訂購額外的領域?我喜歡額外的領域是第一個 – alex 2013-05-16 12:52:41