这是我的密码。真奇怪!如果我将任何静态值替换为$s\\u字符串,它就可以正常工作。提前感谢您的帮助。
$s_string = !empty($_GET[\'q\']) ? sanitize_text_field($_GET[\'q\']) : \'\';
$custom_fields = new WP_Query(array(
\'post_type\' => \'post_type\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
));
$fields = $custom_fields->posts;
$post_ids = array();
foreach ($fields as $post) {
$post_ids[] = $post->ID;
}
if( count( $post_ids ) > 1 ) {
$sub_meta_queries = array();
foreach( $post_ids as $value ) {
$sub_meta_queries[] = array(
\'key\' => $value,
\'value\' => $s_string,
\'compare\' => \'LIKE\'
);
}
$meta_queries[] = array_merge( array( \'relation\' => \'OR\' ), $sub_meta_queries );
} else {
$meta_queries[] = array(
\'key\' => $post_ids,
\'value\' => sanitize_text_field( $s_string ),
\'compare\' => \'LIKE\'
);
}