Search
 
SCRIPT & CODE EXAMPLE
 

PHP

delete uploaded media file wp using code

function delete_unattached_attachments(){
	$attachments = get_posts( array(
	'post_type' => 'attachment',						
	'numberposts' => -1,	 	  								
	'fields' => 'ids', 
	'post_parent' => 0,
		));									
		if ($attachments) {		 		
			foreach ($attachments as $attachmentID){
				$attachment_path = get_attached_file( $attachmentID); 
				//Delete attachment from database only, not file
				$delete_attachment = wp_delete_attachment($attachmentID, true);
				//Delete attachment file from disk
				$delete_file = unlink($attachment_path);					
			}					
		}				
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to add cutom menu option in wordpress 
Php :: decode utf-8 php 
Php :: laravel migrate only one table 
Php :: php remove query param from url 
Php :: string to int laravel 
Php :: the requested php extension ext-intl * is missing from your system ubuntu 
Php :: php replace 
Php :: phpmyadmin import size limit 
Php :: laravel export make comman 
Php :: get current page php 
Php :: guzzlehttp post json example 
Php :: add csrf token laravel 
Php :: laravel artisan progress bar 
Php :: laravel convert number to si 
Php :: mobile number validation in laravel 8 
Php :: laravel join query sum example 
Php :: cut out the beginning of the text in php 
Php :: laravel migration add column after 
Php :: get the page content in wordpress 
Php :: scan all directories and files php 
Php :: check string in php 
Php :: php read json request body 
Php :: laravel model increase the value by one 
Php :: php if post exists 
Php :: codeigniter query builder order by 
Php :: pdo turn on errors 
Php :: explode function in laravel 
Php :: carbon finer 
Php :: command to run php file on chrome 
Php :: how to create a get route in Laravel 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =