也许回答有点晚,但我有一个类似的场景,希望与大家分享解决方案。
在里面functions.php
对于主题(创建插件也可以),我使用\'add_attachment\'
钩子根据每个新上传的文件创建新帖子(自定义帖子类型“talk”)。当然,这个示例可能需要一些改进,但这对解析上载的每个媒体附件都有用。
<?php
function cpt_from_attachment($attachment_ID)
{
global $current_user;
get_currentuserinfo();
$attachment_post = get_post( $attachment_ID );
$type = get_post_mime_type($attachment_ID);
if(strpos($type, \'audio\') === 0)
{
// Create new custom post object only for audio files
$my_post = array(
\'post_title\' => $attachment_post->post_title,
\'post_content\' => $attachment_post->post_content,
\'post_type\' => \'talk\',
\'post_author\' => $current_user->ID
);
// Insert the custom post into the database
$post_id = wp_insert_post( $my_post );
wp_update_post( array(
\'ID\' => $attachment_ID ,
\'post_parent\' => $post_id
)
);
wp_set_post_terms( $post_id, get_post_meta($attachment_ID, "artist", true), \'speaker\' );
}
}
add_action("add_attachment", \'cpt_from_attachment\');