admin管理员组文章数量:1277296
I found this code.
But not work for me. Where to insert the code? I try
wp-content/theme/mytheme/functions.php - not work.
wp-includes/post.php - not work.
wp-includes/functions.php - not work.
And I make plugin (but this the first), not work. Plugin download.
My Wordpress version is 4.2.2.
Big Thanks, and sorry I'm rookie!
I found this code.
But not work for me. Where to insert the code? I try
wp-content/theme/mytheme/functions.php - not work.
wp-includes/post.php - not work.
wp-includes/functions.php - not work.
And I make plugin (but this the first), not work. Plugin download.
My Wordpress version is 4.2.2.
Big Thanks, and sorry I'm rookie!
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked May 15, 2015 at 7:50 AronAron 133 bronze badges 3 |1 Answer
Reset to default 3Just for clarity: borrowing from this answer, add the following to your theme's functions.php
:
function wpse_188427_delete_post_media( $post_id ) {
$attachments = get_posts(
array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'any',
'post_parent' => $post_id,
)
);
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID );
}
}
add_action( 'before_delete_post', 'wpse_188427_delete_post_media' );
// Uncomment the following line if you also want to delete media when the post is trashed
// add_action( 'wp_trash_post', 'wpse_188427_delete_post_media' );
本文标签: pluginsDelete Associated Media Upon PagePost Deletion
版权声明:本文标题:plugins - Delete Associated Media Upon PagePost Deletion 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741276392a2369754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp-includes/post.php
,wp-includes/functions.php
, never edit those files – Kumar Commented May 15, 2015 at 9:23