'LIKE query not returning data as expected - WordPress
I really don't know what's the issue. I think my code is OK but the output is wrong. I don't know anything about WordPress, please help me.
elseif ($_GET['search']) {
$args = array(
'post_type' => 'head_to_toe_videos',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'post_title',
'value' => $_GET['search'],
'compare' => 'LIKE',
)
),
'posts_per_page' => 12,
);
}
Solution 1:[1]
Your query is correct but need to execute you query like this:
$the_query = new WP_Query( $args );
$result = $the_query->get_results();
echo "<pre>"; print_r($result); exit;
Solution 2:[2]
Try the below code your problem will solve.
elseif ($_GET['search'] != '') {
$args = array(
'post_type' => 'head_to_toe_videos',
'post_status' => 'publish',
'meta_key' => 'post_title',
'meta_query' => array(
array(
'key' => 'post_title',
'value' => $_GET['search'],
'compare' => 'LIKE',
)
),
'posts_per_page' => 12,
);
$result = new WP_Query( $args );
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rajeev Singh |
Solution 2 | Anjan |