From f468c49e973bc3cede3dfe7ab54585067db86bb0 Mon Sep 17 00:00:00 2001 From: savvasha Date: Sat, 18 Dec 2021 12:59:47 +0200 Subject: [PATCH] FIX: Player list not loading - too many resources Replace direct db request with get_posts() function for better performance --- includes/sp-core-functions.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index e7593f62..5d6928ad 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1923,15 +1923,24 @@ function sp_has_shortcodes( $content, $tags ) { /** * Check if a custom flag was uploaded from the user * - * @return bool + * @return string */ function sp_flags( $nationality ) { $nationality = strtolower( $nationality ); $flag = ''; - global $wpdb; - $flag_post_id = intval( $wpdb->get_var( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value LIKE '%/$nationality'" ) ); - if ( $flag_post_id ) { - $flag_src = wp_get_attachment_image_url( $flag_post_id, array( 23, 15 ), false ); + $custom_flag_post_id = false; + $args = array( + 'post_type' => 'attachment', + 'title' => $nationality, + 'posts_per_page' => 1, + 'fields' => 'ids', + ); + $custom_flag = get_posts( $args ); + if( $custom_flag ){ + $custom_flag_post_id = $custom_flag[0]; + } + if ( $custom_flag_post_id ) { + $flag_src = wp_get_attachment_image_url( $custom_flag_post_id, array( 23, 15 ), false ); $flag = '' . $nationality . ''; } else { $flag = '' . $nationality . '';