What function builds the Search Query

This topic contains 6 replies, has 3 voices, and was last updated by  DR 8 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #25734

    dave@ocl.ie
    Buyer
    Post count: 59

    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
    dave

    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’) 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

    #25735

    dave@ocl.ie
    Buyer
    Post count: 59

    Hi

    Just to clarify

    Im talking about the GD Search widget..

    Thanks
    dave

    #25740

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi 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

    #25747

    dave@ocl.ie
    Buyer
    Post count: 59

    Hi Stiofan

    I have a Place (I call it a Showroom)
    One user can have one showroom

    I also have a custom post type called Portfolio
    One user can have many portfolio Posts

    SO 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, 10

    So bascially I want to find out where I can add in the OR part of the query above.

    Thanks again

    dave

    #25751

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    ok 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;
    }
    #25752

    dave@ocl.ie
    Buyer
    Post count: 59

    Excellent.

    Thanks for that Stiofan, I will try that a bit later today..

    dave

    #45808

    DR
    Expired Member
    Post count: 78
    This reply has been marked as private.
Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket