我的问题是,有没有办法将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.
*/