我对自定义WP\\U查询有问题。查询参数包括:
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'adressen\',
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'adresse_anzeigen_%_anzeige_branche\',
\'compare\' => \'LIKE\',
\'value\' => $clientId
),
array(
\'key\' => \'adresse_anzeigen_%_anzeige_aktiv\',
\'compare\' => \'=\',
\'value\' => "1"
)
)
);
(元键模式是从高级自定义字段预定义的)
我在WP\\u查询对象转储中遇到的问题,WordPress将其转换为:
SELECT wp_2_posts.* FROM wp_2_posts
INNER JOIN wp_2_postmeta ON ( wp_2_posts.ID = wp_2_postmeta.post_id )
INNER JOIN wp_2_postmeta AS mt1 ON ( wp_2_posts.ID = mt1.post_id )
WHERE 1=1 AND
(
(
wp_2_postmeta.meta_key = \'adresse_anzeigen_{783ec3ed63725295bd6fd75a91ca47bfebd15fa5b4aac1ab7eafd49f682034e6}_anzeige_branche\' AND
wp_2_postmeta.meta_value LIKE \'{783ec3ed63725295bd6fd75a91ca47bfebd15fa5b4aac1ab7eafd49f682034e6}203{783ec3ed63725295bd6fd75a91ca47bfebd15fa5b4aac1ab7eafd49f682034e6}\'
)
AND
(
mt1.meta_key = \'adresse_anzeigen_{783ec3ed63725295bd6fd75a91ca47bfebd15fa5b4aac1ab7eafd49f682034e6}_anzeige_aktiv\' AND
mt1.meta_value = \'1\'
)
)
AND wp_2_posts.post_type = \'adressen\'
AND
(
wp_2_posts.post_status = \'publish\' OR
wp_2_posts.post_status = \'acf-disabled\' OR
wp_2_posts.post_status = \'private\'
)
GROUP BY wp_2_posts.ID
ORDER BY wp_2_posts.post_title ASC
%号和引号不是数字?有人能解释一下原因吗?
最合适的回答,由SO网友:Mark Kaplun 整理而成
作为dev note for 4.8.3 意味着,您需要使用$wpdb->remove_placeholder_escape
方法类似于
global $wpdb;
add_filter(\'posts_request\',array($wpdb, \'remove_placeholder_escape\'));
非常未经测试。