2014-03-19 32 views

回答

1

这些字段存储为某职位的元数据。从插件的源代码(管理员 - 保存 - data.php):

update_post_meta($post->ID,"_staff_member_email",$_POST["_staff_member_email"]); 

通常你能够看到这些修改帖子的时候,但是,随着_前缀的自定义字段是看不见的。此特定元数据与自定义帖子相关联,所以当您查看员工列表帖子时,它会“加载”。对于手动查询,请在wp_postmeta表中查找标记为__ __ __ __ __mail的meta_key。

如何使用WP_Query执行此查询的具体示例位于shortcode附近的user-view-show-staff-list.php文件中。这里是简码功能的重构的版本:

function get_all_staff_info() { 
    $ret = array(); 
    $staff = new WP_Query(array(
     "post_type" => "staff-member", 
     "posts_per_page" => -1, 
     "orderby" => "menu_order", 
     "post_status" => "publish" 
    )); 

    if($staff->have_posts()) { 
     while($staff->have_posts()) { 
      $staff->the_post(); 
      $custom = get_post_custom(); 

      $ret[] = array(
       "name" => get_the_title(), 
       "name_slug" => basename(get_permalink()), 
       "title" => $custom["_staff_member_title"][0], 
       "email" => $custom["_staff_member_email"][0], 
       "phone" => $custom["_staff_member_phone"][0], 
       "bio" => $custom["_staff_member_bio"][0] 
      ); 
     } 
     wp_reset_query(); 
    } 
    return($ret); 
} 

有了这个功能,你所要做的就是调用$staff = get_all_staff_info();和循环穿过。为了便于阅读,我省略了几个可以在上述文件中找到的字段,但输出看起来像一个标准数组:

Array (
    [0] => Array (
     [name] => Cookie 
     [name_slug] => cookie 
     [title] => Second cat 
     [email] => [email protected] 
     [phone] => 123-456-7890 
     [bio] => Meow. 
    ) 
    [1] => Array (
     [name] => Lily 
     [name_slug] => lily 
     [title] => First cat 
     [email] => [email protected] 
     [phone] => 555-555-5555 
     [bio] => Meow? Meow. Meoow? 
    ) 
) 
+0

谢谢pp19pp。你也知道,我怎样才能得到每个成员的照片网址? – yab86

+0

user-view-show-staff-list.php文件中有几行可供您重新调整用途。查找照片和photo_url行并将它们添加到$ ret数组中。 – pp19dd

+0

非常感谢你pp19dd! – yab86