0

I wanted to get the Post ID of a post from another website, but it was not in the url, but it was in the Response Header. enter image description here

When I output the Response Header, the Post ID does not appear on the output. Do you have a solution for getting the Post ID ?

enter image description here

2
  • 1
    You might be able to use the remote site's REST API. A URL like https://example.com/wp-json/v2/posts/?slug=the-slug-you-want would return the post(s) with that slug, and in the post's/posts' JSON objects the ID is available.
    – Pat J
    Commented Nov 15, 2021 at 19:26
  • Really Really Thank You Mr Pat j. ♥ The solution : example.com/wp-json/wp/v2/posts/?slug=the-slug-you-want Commented Nov 15, 2021 at 19:53

1 Answer 1

2

WordPress's REST API should provide the information you need.

If you're after a post with the slug the-slug-you-want, then you can request the data about any post(s) with that slug using the URL https://example.com/wp-json/v2/posts/?slug=the-slug-you-want. This returns the post(s) with that slug, and in the post's/posts' JSON objects the ID is available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.