prefix . 'fbv'; $fbv_rel_table = $wpdb->prefix . 'fbv_attachment_folder'; // Folder ID from previous step (or hardcoded to 1) $folder_id = 1; // Attachment ID (or list of IDs) $attachment_ids = [26913]; foreach ($attachment_ids as $attachment_id) { // Check if relationship exists $existing = $wpdb->get_row( $wpdb->prepare("SELECT folder_id FROM $fbv_rel_table WHERE attachment_id = %d", $attachment_id) ); if ($existing) { // Update existing relationship $wpdb->update( $fbv_rel_table, array('folder_id' => $folder_id), array('attachment_id' => $attachment_id) ); echo "Updated attachment $attachment_id to folder $folder_id\n"; } else { // Insert new relationship $wpdb->insert( $fbv_rel_table, array( 'folder_id' => $folder_id, 'attachment_id' => $attachment_id ) ); echo "Assigned attachment $attachment_id to folder $folder_id\n"; } } ?>