1

I'm using wordpress REST API for sending posts. I uploaded the media already on the wordpress and i have the urls, now I want while sending the post request for creating a post, i could give it the featured image url like other fields easily.

Is there any way to do this?

2

When you create or update a post, you can pass a featured_media argument in the POST data containing the media file's post ID. (It appears you need to have the media item's post ID, not the URL, for this to work.)

  • Is there anyway to get the id of the media by its url in wordpress? – Amirition Sep 10 '18 at 16:25
  • 2
    @Amirition wordpress.stackexchange.com/questions/6645/… – admcfajn Sep 10 '18 at 16:31
  • @pat-j Since I cant pass the url with the request, do I have to register a custom endpoint for this or there is a way for sending custom parameters to this route ? – Amirition Sep 10 '18 at 20:18
  • You might have to make a custom endpoint that returns the attachment's ID, using attachment_url_to_postid(), on the REST API server. – Pat J Sep 10 '18 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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