What function builds the Search Query
This topic contains 6 replies, has 3 voices, and was last updated by DR 9 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: search
-
AuthorPosts
-
December 29, 2014 at 11:59 am #25734
Hi there
Im trying to tweak the main query that is built up from entering a search word and clicking the search button.
I can see the query using SQL Profiler Plugin (see below) but I cannot find where this query is created so that I can change it.
Can you please point me to the correct function.
thanks
daveSELECT SQL_CALC_FOUND_ROWS wp_posts.*, wp_geodir_gd_place_detail.* FROM wp_posts INNER JOIN wp_geodir_gd_place_detail ON (wp_geodir_gd_place_detail.post_id = wp_posts.ID) WHERE 1=1 AND ( ( wp_posts.post_title LIKE “%renovation%” ) OR ( wp_posts.post_content LIKE “%renovation%”) OR ( wp_posts.ID IN( SELECT wp_term_relationships.object_id as post_id FROM wp_term_taxonomy, wp_terms, wp_term_relationships WHERE wp_term_taxonomy.term_id = wp_terms.term_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ( ‘gd_place_tags’,’gd_placecategory’ ) AND (wp_terms.name LIKE”%renovation%” OR wp_terms.name IN (“renovation”)) ) ) ) AND wp_posts.post_type IN (‘gd_place’) AND (wp_posts.post_status = ‘publish’) ORDER BY wp_posts.post_title asc, wp_geodir_gd_place_detail.is_featured asc, wp_posts.post_date desc, wp_posts.post_title LIMIT 0, 10
December 29, 2014 at 12:23 pm #25735Hi
Just to clarify
Im talking about the GD Search widget..
Thanks
daveDecember 29, 2014 at 1:01 pm #25740Hi Dave,
The query is not really all in one place and can be changed depending on what addons you have installed, it can mostly all be changed with hooks and filters. I am not sure how advanced your PHP/SQL knowledge is but if you let me know what you are trying to achieve i can better help you.
Thanks,
Stiofan
December 29, 2014 at 1:30 pm #25747Hi Stiofan
I have a Place (I call it a Showroom)
One user can have one showroomI also have a custom post type called Portfolio
One user can have many portfolio PostsSO a User can have One Showroom with Many Portfolios
I have modified the related listings to show all the portfolios for the showroom. This all works fine.
But the search is only searching the Place post (showroom) which is fine but I want the results to also show Showrooms for Portfolios that contain the search words.
Here is the query I want (and this works fine when I use SQL executioner Plugin)
SELECT SQL_CALC_FOUND_ROWS wp_posts.*, wp_geodir_gd_place_detail.* FROM wp_posts INNER JOIN wp_geodir_gd_place_detail ON (wp_geodir_gd_place_detail.post_id = wp_posts.ID) WHERE 1=1 AND
( ( wp_posts.post_title LIKE “%renovation%” ) OR ( wp_posts.post_content LIKE “%renovation%”) OR ( wp_posts.ID IN( SELECT wp_term_relationships.object_id as post_id FROM wp_term_taxonomy, wp_terms, wp_term_relationships WHERE wp_term_taxonomy.term_id = wp_terms.term_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ( ‘gd_place_tags’,’gd_placecategory’ ) AND (wp_terms.name LIKE”%renovation%” OR wp_terms.name IN (“renovation”)) ) )
)
AND wp_posts.post_type IN (‘gd_place’)
AND (wp_posts.post_status = ‘publish’)OR
wp_posts.post_author in (
SELECT wp_posts.post_author FROM wp_posts INNER JOIN wp_geodir_gd_portfolio_detail ON (wp_geodir_gd_portfolio_detail.post_id = wp_posts.ID) WHERE 1=1 AND ( ( wp_posts.post_title LIKE “%renovation%” ) OR ( wp_posts.post_content LIKE “%renovation%”) OR ( wp_posts.ID IN( SELECT wp_term_relationships.object_id as post_id FROM wp_term_taxonomy, wp_terms, wp_term_relationships WHERE wp_term_taxonomy.term_id = wp_terms.term_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ( ‘gd_portfolio_tags’,’gd_portfoliocategory’ ) AND (wp_terms.name LIKE”%renovation%” OR wp_terms.name IN (“renovation”)) ) ) ) AND wp_posts.post_type IN (‘gd_portfolio’) AND (wp_posts.post_status = ‘publish’)
)
ORDER BY wp_posts.post_title asc, wp_geodir_gd_place_detail.is_featured asc, wp_posts.post_date desc, wp_posts.post_title LIMIT 0, 10So bascially I want to find out where I can add in the OR part of the query above.
Thanks again
dave
December 29, 2014 at 1:53 pm #25751ok just FYI we will be working on a universal search in the new year that will likely achieve what you want but for now you would have to look at the core function “searching_filter_where” in listing_filters.php 581 and then add your own filter and functions to then add a OR after, u could do that like this
add_filter('posts_where', 'my_searching_filter_where', 5); function my_searching_filter_where($where){ global $wpdb,$geodir_post_type,$table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s,$s_A,$s_SA,$search_term; $my_new_query = " MY SQL HERE "; $where = $where.$my_new_query; return $where; }
December 29, 2014 at 1:55 pm #25752Excellent.
Thanks for that Stiofan, I will try that a bit later today..
dave
July 15, 2015 at 10:03 am #45808This reply has been marked as private. -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket