【问题标题】:Making Wordpress user metadata available to Rest-API使 WordPress 用户元数据可用于 Rest-API
【发布时间】:2023-03-03 05:26:21
【问题描述】:

我正在构建一个与我的 Wordpress 网站 Rest API 相关联的 Ionic 应用程序。虽然我已经弄清楚如何填充帖子和页面数据,但我很难填充用户数据。

具体来说,我正在尝试通过名为 UPME(用户配置文件变得简单)的第三方插件访问存储为 usermeta 的用户数据。它作为用户元数据存储在数据库中。

这是我设想从 API 拉入应用程序的图像。

比如user_id: 43 meta_key: 数据库内的linkedin。

谁能给我一个例子,说明我可以在我的functions.php中做什么,以便能够将每个用户与{...} meta_keys填充到API中以供外部访问?

编辑:这是我对它应该做什么的理解

我需要 Wordpress 中的一些功能,使我的 Rest-API 可以使用以下功能:

• Get list of all users
    • For all users {
    • If user upme_user_profile_status: ACTIVE 
        • Get the following usermeta: [
        first_name
        last_name
        company_name
        company_title
        user_email
        business_phone
        facebook
        twitter
        linkedin
        ]
    }

这将在 API 中公开访问。

【问题讨论】:

    标签: wordpress ionic-framework api-design wordpress-rest-api


    【解决方案1】:

    我认为this 应该可以帮助您。以及WP user query供参考。

    以无序列表显示所有订阅者的示例。

    <?php
    $blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
    // Array of WP_User objects.
    foreach ( $blogusers as $user ) {
        echo '<span>' . esc_html( $user->user_email ) . '</span>';
    }
    

    按特定字段查询的示例。

    <?php
    $blogusers = get_users( array( 'fields' => array( 'display_name' ) ) );
    // Array of stdClass objects.
    foreach ( $blogusers as $user ) {
        echo '<span>' . esc_html( $user->display_name ) . '</span>';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 2019-03-05
      相关资源
      最近更新 更多