쿼리 라이브러리
쿼리 라이브러리다른 WordPress 사이트에 저장된 사용자 데이터 가져오기

다른 WordPress 사이트에 저장된 사용자 데이터 가져오기

이 쿼리는 두 사이트 간의 공통 식별자로 사용자의 슬러그를 사용하여, 다른 WordPress 사이트에 저장된 사용자 데이터를 가져옵니다.

리모트 사이트의 /users REST API 엔드포인트를 실행하면서 대상 사용자의 슬러그를 전달하여 해당 결과만 가져오는 방식으로 동작합니다.

query GetUserSlugs {
  users(pagination: { limit: -1 }) {
    id
    slug
      @export(
        as: "userSlugs",
        type: LIST,
      )
  }
}
 
query FetchUserDataFromAnotherWPSite(
  # URL of the remote /guides/query/users 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
    }
  )
}