Query string form $_GET[‘value’] is not working as meta value in wp_query

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.

$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’
);
}

Read more here:: Query string form $_GET[‘value’] is not working as meta value in wp_query

Leave a Reply

Your email address will not be published. Required fields are marked *