I have a search page where if the main search returns 0 results then the following query will be used.
The code is
$num_res = $wp_query->post_count;
$get_search_term = get_search_query();
if($num_res == 0)
{
$args = array(
'post_type' => 'resources',
'meta_key' => 'resource_txt',
'meta_value' => $get_search_term,
'meta_compare' => 'LIKE' );
$custom_query = new WP_Query( $args );
}
Now I am getting an error which says "Not unique table/alias: 'wp_postmeta'"
When I print the second query in browser it says,
SELECT SQL_CALC_FOUND_ROWS
DISTINCT wp_posts.ID FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE 1=1
AND ( ( wp_postmeta.meta_key = 'resource_txt' AND CAST(wp_postmeta.meta_value AS CHAR) LIKE '%insurance claim%' ) )
AND wp_posts.post_type = 'resources'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
Is it like, I have to close the previous query and then run the custom query. Any help is highly appreciated.