Created
October 31, 2022 20:57
-
-
Save hellofromtonya/de5d59a9c42820f3395667883fac3f19 to your computer and use it in GitHub Desktop.
Must-use test file for Trac 56933.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'loop_start', 'test_56933', 12 ); | |
// For testing https://core.trac.wordpress.org/ticket/56933. | |
function test_56933() { | |
global $wpdb; | |
$search_string = 'hello'; | |
$sql = $wpdb->prepare("(select $wpdb->posts.ID, post_title, {$wpdb->prefix}mgmlp_folders.folder_id, pm.meta_value as attached_file, 'a' as item_type | |
from $wpdb->posts | |
LEFT JOIN {$wpdb->prefix}mgmlp_folders ON($wpdb->posts.ID = {$wpdb->prefix}mgmlp_folders.post_id) | |
LEFT JOIN $wpdb->postmeta AS pm ON (pm.post_id = $wpdb->posts.ID) | |
LEFT JOIN $wpdb->users AS us ON ($wpdb->posts.post_author = us.ID) | |
where post_type = 'mgmlp_media_folder' and pm.meta_key = '_wp_attached_file' and SUBSTRING_INDEX(pm.meta_value, '/', -1) like '%%%s%%') | |
union all | |
(select $wpdb->posts.ID, post_title, {$wpdb->prefix}mgmlp_folders.folder_id, pm.meta_value as attached_file, 'b' as item_type | |
from $wpdb->posts | |
LEFT JOIN {$wpdb->prefix}mgmlp_folders ON( $wpdb->posts.ID = {$wpdb->prefix}mgmlp_folders.post_id) | |
LEFT JOIN $wpdb->postmeta AS pm ON (pm.post_id = $wpdb->posts.ID) | |
LEFT JOIN $wpdb->users AS us ON ($wpdb->posts.post_author = us.ID) | |
where post_type = 'attachment' and pm.meta_key = '_wp_attached_file' and SUBSTRING_INDEX(pm.meta_value, '/', -1) like '%%%s%%') order by attached_file", $search_string, $search_string); | |
echo "<pre>"; | |
echo $sql; | |
echo "</pre>"; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment