문제

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