admin管理员组文章数量:1426183
Here is my code.How strange! if I put any static value replacing $s_string, it's working fine. Thanks in advance for any help.
$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'
);
}
Here is my code.How strange! if I put any static value replacing $s_string, it's working fine. Thanks in advance for any help.
$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'
);
}
Share
Improve this question
edited May 22, 2019 at 13:51
Rafiq
asked May 22, 2019 at 12:11
RafiqRafiq
1001 gold badge1 silver badge9 bronze badges
3
|
1 Answer
Reset to default 0Are you sure the $_GET['q']
param is set?
Try:
$s_string = ( isset($_GET['q]) && !empty($_GET['q']) ) ? sanitize_text_field($_GET['q']) : '';
本文标签: Query string form GET39value39 is not working as meta value in wpquery
版权声明:本文标题:Query string form $_GET['value'] is not working as meta value in wp_query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745473357a2659849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$s_string
anywhere, so I’m not sure what you’re expecting to happen? What is that variable supposed to be? – Jacob Peattie Commented May 22, 2019 at 12:16error_log( $_GET['q'] );
and check your PHP error log to see what the value of$_GET['q']
is. – jasonp Commented May 23, 2019 at 22:17