Skip to content

Commit 551634e

Browse files
swissspidyCopilot
andauthored
Update src/Media_Command.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5bdea55 commit 551634e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Media_Command.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,15 @@ private function find_duplicate_attachment( $basename ) {
740740

741741
$result = $wpdb->get_var(
742742
$wpdb->prepare(
743-
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attached_file' AND (meta_value = %s OR RIGHT(meta_value, %d) = %s) LIMIT 1",
743+
"SELECT p.ID
744+
FROM {$wpdb->posts} p
745+
INNER JOIN {$wpdb->postmeta} pm
746+
ON p.ID = pm.post_id
747+
WHERE p.post_type = 'attachment'
748+
AND p.post_status != 'trash'
749+
AND pm.meta_key = '_wp_attached_file'
750+
AND ( pm.meta_value = %s OR RIGHT(pm.meta_value, %d) = %s )
751+
LIMIT 1",
744752
$basename,
745753
$slash_basename_length,
746754
$slash_basename

0 commit comments

Comments
 (0)