2012-07-26 93 views
1

我有一个问题,即将自定义字段添加到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

回答

2

右键我发现到底是工作代码...

/* 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-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'); 

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-profs2', $_POST['u-profs2']); 
} 

/* Google Rel Author */ 

function google_rel_author_in_document_head() { 
global $post; 
$author_id=$post->post_author; 
?> 
<link rel="author" href="<?echo get_user_meta($author_id, 'u-profs2', true);?>"/> 
<? 
} 
add_action('wp_head', 'google_rel_author_in_document_head',99); 
+0

在哪文件把这个代码...即时新的wordpress ... – harsh4u 2013-04-20 19:12:24

+0

你知道如何订购额外的领域?我喜欢额外的领域是第一个 – alex 2013-05-16 12:52:41

相关问题