获取成员数据表单插件staff-member-list

时间:2014-03-19 12:51:35

标签: php wordpress plugins

我想收到所有会员的电子邮件。我无法弄清楚存储名称,电话,电子邮件等数据的位置。在数据库?我无法在数据库中找到这些数据。

如何使用我自己的PHP文件获取所有电子邮件?

Plugin Simple Staff List

1 个答案:

答案 0 :(得分:1)

这些字段存储为帖子的元数据。从插件源代码(admin-save-data.php):

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

通常,您在编辑帖子时可以看到这些内容,但是,前缀为_的自定义字段是不可见的。此特定元数据与自定义帖子相关联,因此当您查看员工列表帖子时,它会“加载”。对于手动查询,请查看wp_postmeta表以获取标记为 _staff_member_email 的meta_key。

使用WP_Query执行此查询的具体示例位于短代码附近的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] => cookie@example.com
        [phone] => 123-456-7890
        [bio] => Meow.
    )
    [1] => Array (
        [name] => Lily
        [name_slug] => lily
        [title] => First cat
        [email] => lily@example.com
        [phone] => 555-555-5555
        [bio] => Meow? Meow. Meoow?
    )
)