WordPress媒体作为自定义帖子类型 [英] WordPress Media as a Custom Post Type

查看:102
本文介绍了WordPress媒体作为自定义帖子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个WordPress网站,该网站将允许成员上传视频,图像等媒体.他们将以公开格式进行操作,例如:domain.com/upload

I am building a WordPress website that will allow members to upload media such as videos, images, etc. They will do this on a public form at for example: domain.com/upload

该表单将要求提供标题,简短摘要,显示一些可供选择的类别,最后是文件上传器.然后,用户将能够提交表单,该表单将以帖子的形式出现在网站上,但它不仅仅是文字,而是一种媒体.

The form will ask for a Title, a brief summary, show some categories to choose from, and finally a file uploader. The user will then be able to submit the form and it will appear on the site as a post but instead of being just text it is a piece of media.

我创建了一个自定义帖子类型,而且一切似乎都很好,我的问题是如何处理媒体上传,因为默认的WP方法是上传一个项目,然后手动将其插入到帖子中(并且您可以插入任意多的内容).我希望用户在每个帖子中只能上传一个文件,而不必将文件插入帖子中,因为文件本身就是帖子.他们还将能够上传特色图片.

I have created a custom post type and all seems to be fine, the problem I have is how to deal with the media upload, as the default WP method is to upload an item and then manually insert it into the post (and you can have as many inserted as you like). Where as I want users to be only able to upload one file per post and not have to insert the file into a post because the file itself is the post. They will also be able to upload a featured image.

关于如何发展这一点的任何想法?谢谢.

Any ideas on how I can develop this? Thanks.

推荐答案

您可以使用WP上传方法将文件上传到服务器.然后(取决于您上传的媒体类型),您可以在帖子中插入文件的HTML表示形式(例如,解析文本文件,为图像创建标签或嵌入视频).

You could use WP upload methods to upload your file to the server. Then (depending on your upload's media type) you would insert HTML representation of the file into the post (e.g. parse a text file, create tag for image or embed a video).

如果您想查看一些可行的示例,请告诉我.我只是概述一下流程:

If you want to see some working example, please let me know. I just outline the flow:

  • wp-handle_upload()实际上传文件
  • wp_update_post()wp_insert_post(),具体取决于您是创建新用户帖子还是编辑现有帖子.两种方法都需要一个参数-Post对象.那是您放置内容(当然是post_content字段)并发布数据的地方
  • wp-handle_upload() to physically upload a file
  • wp_update_post() or wp_insert_post() depending on whether you're creating a new user post or editing existing one. Both methods require one argument - Post object. That's where you put your content (as a post_content field of course) and post data

这篇关于WordPress媒体作为自定义帖子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆