最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Wordpress REST API: Query media files attached to a custom post type

programmeradmin2浏览0评论

I want to attach an React native app to a Wordpress E-Learning Portal (leveraging the LearnPress-Plugin) to authenticate enrolled students and download audio assets of the course to the app.

The Plugin uses custom post types for courses & lessons.

So after authentication I use the Media Query to retreive the audio assets via Rest Media API

I want to retreive all media assets attached to a certain lesson Id, so I use the parent argument in the query:

/wp-json/wp/v2/media/?media_type=audio&parent={LESSON_POST_ID}

I get empty results.

If I attach the media files to a regular wordpress post, the query works fine

/wp-json/wp/v2/media/?media_type=audio&parent={SOME_REGULAR_POST_ID}

So I guess the problem is that the lessons are custom post types?!

Do you have any solution or any workaround for this?

I could attach all needed media files to a regular post and query for them, but then I need to hardcode the post-id into the app, which I would like to avoid.

Thank you in advance!

Additional info

I attach the media items via AdminPanel->Media

This leads to an insert of the corresponding post_parent Id in the DB.

发布评论

评论列表(0)

  1. 暂无评论