我正在尝试运行一个搜索,对附加了高级自定义字段的用户配置文件进行排序。我正在使用WP用户查询。我搜索的一个字段是repeater字段(business\\u information)及其子字段(business\\u name)。
我正在使用提供的信息ACF documentation page, #4 Sub Custom Field Values
因此,对于我的变量,它如下所示:
function my_posts_where( $where ) {
$where = str_replace("meta_key = \'business_information_%", "meta_key LIKE \'business_information_%", $where);
return $where;
}
add_filter(\'posts_where\', \'my_posts_where\');
if( !empty( $_GET[\'usersearch\'] ) ){
$usersearch = stripslashes( trim($_GET[\'usersearch\']) );
// WP_User_Query arguments
$args = array(
\'role\' => \'Subscriber\',
\'meta_query\' => array(
array(
\'key\' => \'membership_class\',
\'value\' => \'Full\',
\'compare\' => \'=\',
\'type\' => \'CHAR\',
),
array(
\'relation\' => \'OR\',
array(
\'key\' => \'first_name\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'last_name\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'personal_city\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\',
\'type\' => \'CHAR\',
),
array(
\'key\' => \'personal_province\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\',
\'type\' => \'CHAR\',
),
array(
\'key\' => \'treatments\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\',
),
array(
\'key\' => \'business_information_%_business_name\',
\'value\' => $usersearch,
\'compare\' => \'LIKE\',
),
),
),
);
请求输出:
SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_users.* FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) INNER JOIN wp_usermeta AS mt1 ON ( wp_users.ID = mt1.user_id ) INNER JOIN wp_usermeta AS mt2 ON ( wp_users.ID = mt2.user_id ) WHERE 1=1 AND (
(
(
( wp_usermeta.meta_key = \'membership_class\' AND wp_usermeta.meta_value = \'Full\' )
AND
(
( mt1.meta_key = \'first_name\' AND mt1.meta_value LIKE \'%name%\' )
OR
( mt1.meta_key = \'last_name\' AND mt1.meta_value LIKE \'%name%\' )
OR
( mt1.meta_key = \'personal_city\' AND mt1.meta_value LIKE \'%name%\' )
OR
( mt1.meta_key = \'personal_province\' AND mt1.meta_value LIKE \'%name%\' )
OR
( mt1.meta_key = \'treatments\' AND mt1.meta_value LIKE \'%name%\' )
OR
( mt1.meta_key = \'business_information_%_business_name\' AND mt1.meta_value LIKE \'%name%\' )
)
)
AND
(
(
( mt2.meta_key = \'wp_capabilities\' AND mt2.meta_value LIKE \'%\\"Subscriber\\"%\' )
)
)
)
) ORDER BY user_login ASC
现在,我要第一个承认我不知道自己到底在做什么,但其余的搜索都完全按照我的意愿进行。只是business repeater字段没有正确进入搜索查询。据我所知,上述函数应该替换db请求的那一部分,但它没有这样做,我不知道为什么或者如何使其工作,或者它最终应该是什么样子。我一直在谷歌上搜索这个问题,只是找不到答案。一切似乎都与帖子有关,而不是与用户有关,我想知道这是不是我的问题?有人知道有什么可以帮助的吗?