我有一个wordpress网站,它是关于媒体分享的。我上传了mp3文件作为相册,并为每一张专辑创建了一篇文章。但是我想为每个自动上传的mp3文件创建单独的帖子。
我已经尝试了mp3到post插件,但这是不支持的最新版本的wordpress,我已经尝试上传插件,但它不工作。
发布于 2019-04-05 06:03:47
使用do_action( 'add_attachment', $post_ID )钩子,您可以创建相应的帖子。有关参考资料-请参阅帖子函数
要完成上述操作,在活动主题的functions.php中添加以下代码片段-
function action_add_attachment( $post_ID ) {
if( !$post_ID ) return;
$attachment = get_post( $post_ID );
// Create album post object for attachment post ID
$attachment_post = array(
'post_title' => 'Album - ' . $attachment->post_title,
'post_content' => 'Your post content goes here',
'post_status' => 'publish',
'post_author' => $attachment->post_author
);
// Insert the post
wp_insert_post( $attachment_post );
}
add_action( 'add_attachment', 'action_add_attachment', 99 ); https://stackoverflow.com/questions/55528679
复制相似问题