Thư viện QueriesLấy dữ liệu người dùng lưu trữ trên một WordPress site khác
Lấy dữ liệu người dùng lưu trữ trên một WordPress site khác
Query này truy xuất dữ liệu người dùng (từ một WordPress site) được lưu trữ trên một WordPress site khác, sử dụng slug của người dùng làm định danh chung giữa 2 site.
Cách hoạt động là thực thi endpoint REST API /users trên site từ xa, đồng thời truyền các slug của người dùng để chỉ lấy những kết quả tương ứng.
query GetUserSlugs {
users(pagination: { limit: -1 }) {
id
slug
@export(
as: "userSlugs",
type: LIST,
)
}
}
query FetchUserDataFromAnotherWPSite(
# URL of the remote /huong-dan/query/nguoi-dung REST API endpoint
# eg: https://somesite.com/wp-json/wp/v2/users
$endpointURL: URL!
)
@depends(on: "GetUserSlugs")
{
endpoint: _urlAddParams(
url: $endpointURL,
params: {
slug: $userSlugs
}
)
remoteUserData: _sendJSONObjectCollectionHTTPRequest(
input: {
url: $__endpoint,
method: GET
}
)
}