Wp_插入_附件的POST_AUTHER

时间:2013-08-04 作者:Greeso

我正在处理一个自定义主题,在其中我需要以编程方式插入帖子和附件。一个要求是,这些帖子属于非登录并运行操作的用户。

举个例子,一个管理员用户登录到WordPress,并运行此自定义操作。自定义操作将为另外两个用户user1和user2创建建议帖子。

现在,如果user1登录,他/她将看到一篇建议的帖子,他可以选择发布它。

到目前为止,一切都很酷,因为功能wp_insert_post 允许在programattic中插入立柱。此函数采用的参数之一是post_author 可以将其设置为user1或user2的id。

到目前为止,一切都很好。

现在,这些帖子将有附件(图像)。我的问题是,有没有办法添加post_authorwp_insert_attachment? 我在文档中找不到这一点。我需要的附件有相同的作者id作为该职位。目前它采用管理员的id。

谢谢

1 个回复
最合适的回答,由SO网友:Chris_O 整理而成

我的问题是,有没有办法将post\\u作者添加到wp\\u insert\\u附件中?我在文档中找不到这一点。我需要的附件有相同的作者id作为该职位。目前它采用管理员的id。

有时,法典或出版的文件并不能说明全部情况。如果您不了解函数是如何工作的,直接转到源代码总是更好的。如果查看PHP文档块wp_insert_attachment() 你会找到你正在寻找的答案。

/**
 * Insert an attachment.
 *
 * If you set the \'ID\' in the $object parameter, it will mean that you are
 * updating and attempt to update the attachment. You can also set the
 * attachment name or title by setting the key \'post_name\' or \'post_title\'.
 *
 * You can set the dates for the attachment manually by setting the \'post_date\'
 * and \'post_date_gmt\' keys\' values.
 *
 * By default, the comments will use the default settings for whether the
 * comments are allowed. You can close them manually or keep them open by
 * setting the value for the \'comment_status\' key.
 *
 * The $object parameter can have the following:
 *     \'post_status\'   - Default is \'draft\'. Can not be overridden, set the same as parent post.
 *     \'post_type\'     - Default is \'post\', will be set to attachment. Can not override.
 *     \'post_author\'   - Default is current user ID. The ID of the user, who added the attachment.
 *     \'ping_status\'   - Default is the value in default ping status option. Whether the attachment
 *                       can accept pings.
 *     \'post_parent\'   - Default is 0. Can use $parent parameter or set this for the post it belongs
 *                       to, if any.
 *     \'menu_order\'    - Default is 0. The order it is displayed.
 *     \'to_ping\'       - Whether to ping.
 *     \'pinged\'        - Default is empty string.
 *     \'post_password\' - Default is empty string. The password to access the attachment.
 *     \'guid\'          - Global Unique ID for referencing the attachment.
 *     \'post_content_filtered\' - Attachment post content filtered.
 *     \'post_excerpt\'  - Attachment excerpt.
 *
 * @since 2.0.0
 * @uses $wpdb
 * @uses $user_ID
 * @uses do_action() Calls \'edit_attachment\' on $post_ID if this is an update.
 * @uses do_action() Calls \'add_attachment\' on $post_ID if this is not an update.
 *
 * @param string|array $object Arguments to override defaults.
 * @param string $file Optional filename.
 * @param int $parent Parent post ID.
 * @return int Attachment ID.
 */

结束

相关推荐

Wordpress Post Grid

我正在尝试为我的Wordpress帖子创建一个自定义网格。我一直在网上搜索,但我找到的所有教程都使用了列方法,只在列之间交替。因为我现在所做的是不可能的,我需要它实际数出六个缩略图,然后返回一行,然后再做一次。有人知道这方面的好教程/示例吗(它不可能是插件)?非常感谢所有答案。下面的代码是我所拥有的,所以没有包装行。 $categories = get_categories(\'child_of=2\'); foreach ($categories as $category) {