2014-03-19 65 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