gpt4 book ai didi

php - Wordpress:所以我一直在 mysql 查询中直接调用 wp_(tablenames)。纠正此问题的最佳方法是什么?

转载 作者:行者123 更新时间:2023-11-30 22:18:18 25 4
gpt4 key购买 nike

所以我一直在开发wordpress的插件,一直运行很慢,一直在数据库中直接调用wp_usermeta,最近才发现千万不要直接调用,如下:

$getUserdaetails = pdo_query("Select wp_usermeta.user_id, Min(Case meta_key When 'name_of_your_facility' Then meta_value End) GYM_NAME, Min(Case meta_key When 'description_of_the_gym' Then meta_value End) GYM_DESCRIPTION, Min(Case meta_key When 'city_registration' Then meta_value End) GYM_CITY, Min(Case meta_key When 'country_registration' Then (SELECT DISTINCT COUNTRY_MAPPING.COUNTRY_NAME FROM wp_usermeta, COUNTRY_MAPPING WHERE wp_usermeta.meta_key = 'country_registration' AND wp_usermeta.meta_value = COUNTRY_MAPPING.COUNTRY_CODE AND wp_usermeta.user_id = ?) End) GYM_COUNTRY, Min(Case meta_key When 'category' Then (SELECT DISTINCT CATEGORY_MAPPING.CATEGORY_NAME FROM wp_usermeta, CATEGORY_MAPPING WHERE wp_usermeta.meta_key = 'category' AND wp_usermeta.meta_value = CATEGORY_MAPPING.CATEGORY_CODE AND wp_usermeta.user_id  = ?) End) GYM_CATEGORY, Min(Case meta_key When 'image_1' Then (SELECT wp_posts.guid FROM wp_usermeta, wp_posts WHERE wp_usermeta.user_id = ? AND wp_usermeta.meta_key = 'image_1' AND wp_posts.post_type = 'attachment' AND wp_usermeta.meta_value = wp_posts.ID) End) GYM_IMAGE FROM wp_usermeta, wp_posts, COUNTRY_MAPPING WHERE user_id = ?", pdo_real_escape_string($row1[user_id]), pdo_real_escape_string($row1[user_id]), pdo_real_escape_string($row1[user_id]), pdo_real_escape_string($row1[user_id]));

$recordCountTest2 .= pdo_num_rows($getUserdaetails);
foreach($getUserdaetails as $row2){
$html3a .= "Category - <span style='color: #000000;'>{$row2[GYM_CATEGORY]}</span>
.........
";
}

我的问题是,如何最好地更改我的代码,使其与 wordpress/插件兼容?

谢谢

最佳答案

在运行任何 sql 查询“而不是 wp_”时,始终使用 $wpdb->prefix。像下面的例子

$table_name = $wpdb->prefix . "liveshoutbox";

关于php - Wordpress:所以我一直在 mysql 查询中直接调用 wp_(tablenames)。纠正此问题的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37487242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com