global $wpdb;
$image_src = wp_upload_dir()['baseurl'] . "https://wordpress.stackexchange.com/" . _wp_relative_upload_path( $filename );
$query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE guid='$image_src'";
$count = intval($wpdb->get_var($query));
You can use this at the top of your code. Then check the value of $count
. If it’s 0, then you can continue adding the attachment
Related Posts:
- Change Media Uploader default directory
- Using the component outside the editor. select(‘core’) is null
- How to replicate Media Library “Add New” on Plugin Settings Page
- How to enable sorting in custom media uploader in plugin
- Upload multiple images and insert them into custom html code
- wp_editor add media button not working
- Changed media upload path for plugin, but generates error & shows wrong url
- How to destroy or dispose wordpress uploder/manager?
- How do you filter get_media_items by mime type in a custom media upload tab?
- Upload to a specific media folder created by FileBird Lite
- Load images from CDN and custom features to “Add Media” dialogue
- upload image to wordpress media library failed for custom post type
- How can I add an image upload field directly to a custom write panel?
- Enhance Media Manager for Gallery
- Custom collection in media manager?
- Standard location for plugin to save/cache files?
- Adding more options to the instance of an image. (Attachment Display Settings)
- Saving data-URI to media library
- Can I use the wp media uploader for my own plugin?
- Changing upload directory for plugin uploads only
- Upload file to remote storage
- How to extend LINK TO functionality in ATTACHMENT DISPLAY SETTINGS
- how does wp.media javascript library work?
- Why are two functions over-riding each other?
- How can I view all WP generated thumbnails in Media Manager?
- Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
- WordPress Media mime type filter problem 4.0
- Bridge WordPress Media API with custom tinyMCE plugin [closed]
- How to get an image transferred via FTP or script to appear in Media Manager?
- Add Additional File Info (jpeg compression & file size) settings to Edit Images Screen
- Is it possible to modify the media library admin screen?
- Proper way to hook wp_get_attachment_url
- Getting Details Of Uploaded Image
- Sharing a common set of image files for media library, across all sites within multisite
- Uploading images from a custom page using blueimp uploader?
- Hook to get image filename when it is uploaded
- How to send email in wordpress with more than one attachments
- Using the default wordpress uploader inside plugin
- Files automatically added
- What filter should I use to insert a button inside on Media>Add New
- Changing upload dir in a plugin regardless of post type
- Plugin writing: access file that was just uploaded
- Custom delete option button in plugin settings
- Create a new post using rest api and save featured image using an external image url
- Why is the temporary upload always 4.1K
- Redirect to another page using contact form 7? [closed]
- WordPress Specified file failed upload test
- Run a function when new image is uploaded in media library
- zip unzip attachments in wordpress
- How to create a digital product download link that can’t be used twice?
- How to submit/upload data to database and in specific folder?
- Cleaning a filename after image sideloading a url that contains `%20`
- Get audio metadata on file upload
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- Why doesn’t update_post_meta work for certain strings?
- wp.media Uncaught TypeError: Cannot read properties of undefined (reading ‘state’)
- How to create wordpress media library UI on plugin page
- How to upload large media file in chunks, without any plugin?
- wp.media gallery collection sometimes undefined
- Insert and read media from the WordPress library and call in the plugin
- How to copy the all WordPress media items to another custom plugin folder?
- Can’t load a script in my plugin page
- function add custom fields to media gallery
- Trying to rename a file upload as the hash of file content on wordpress
- Home page is not loading, where in other pages are displaying on the site
- WordPress5.2.3: Better File Download Plugin validation issue
- WordPress discards PNG file when uploading plugin file
- Hook for validating and rejecting frontend image upload
- Media Upload to custom database and Custom Directory
- WordPress Dropdown image select
- Creating custom Insert Media page
- Displaying $_FILES data (simlar to $_POST)
- Changing upload directory for plugin uploads only
- Thumbnails for media Library images
- Remove image in post when it’s removed in media library
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Open media box library from link
- upload script in plugin development [duplicate]
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- How to delete resized (cropped) image uploads and prevent future resizing?
- How to show all available images in WP’s media library when using the Polylang plugin?
- Understanding WordPress functions’ naming conventions
- Way to force media uploader use custom image size
- How to use the settings API to set multidimensional arrays
- How to allow Unfiltered HTML in a wordpress multisite install
- Rewrite Point Doesn’t Work on Custom Taxonomy
- wp_remote_get keeps timing out
- Append varible to url or set session
- WordPress publish_post hook not getting featured image and meta on first publish, but works on updating title
- Add function after the_content
- How to add custom view links to wp-admin/post.php?
- How do I get variables from my plugin’s settings page?
- How To Protect Plugin Display From Being Affected By Theme’s CSS
- wp_schedule_event not executing function call, even with add_action
- How to query a nested field in wordpress api using _fields param
- using wordpress acf shortcods in tables goes outside the table
- remove different admin menu for specific users
- Shortcode from a plugin not working
- Can’t get query string in ajax call
- WP Cron registers hook without any action (does not call the function)