I am looking for solution to auto delete images of old posts in WordPress site. I want to hold images of current 50 posts, others should be deleted automaticly. It can be function to delete on time interval, or function to hold only images of last 50 posts. Does anyone know function or some plugin which can do this or similar things, to automaticly ddelete older images?

有帮助吗?

解决方案

http://wordpress.org/plugins/cleanup-images/

or in code add hook with delete post

function 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 ) {
        if ( false === wp_delete_attachment( $attachment->ID ) ) {
            // Log failure to delete attachment.
        }
    }
}

try this

hope it will use full for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top