an
groups-icon

Advanced Search AND OR sql results issue with custom field

Wait a minute... This content is very very old. We no longer sell or support this theme version. New Topics
  • Version 9
    Brian Scoby
    0 points
    Beginner

    Hi

    I am trying to figure out how to get my advanced serach working

    My Fields
    Category Listing
    State
    City
    Facilities (custom field multi select)

    if I search by Category Listing, State, City the search works
    Cork -> Cork City

    Sql Output:

    INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
    INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
    WHERE 1=1
    AND (
    wp_term_relationships.term_taxonomy_id IN (41)
    )
    AND (((wp_posts.post_title LIKE ‘%%’) OR (wp_posts.post_content LIKE ‘% %’)))
    AND
    (
    ( wp_postmeta.meta_key = ‘map-state’ AND CAST(wp_postmeta.meta_value AS CHAR) = ‘Cork’ )
    AND
    ( mt1.meta_key = ‘map-city’ AND CAST(mt1.meta_value AS CHAR) = ‘Cork City’ )

    ) AND wp_posts.post_type = ‘listing_type’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’)
    GROUP BY wp_posts.ID ORDER BY wp_posts.post_title , wp_posts.post_date DESC LIMIT 0, 10

    If I search by Category Listing, State, City and My Custom Field the search doesn’t work

    Cork->Cork-City->Wheelchair Access

    Sql Output

    SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    INNER JOIN wp_postmeta ON
    ( wp_posts.ID = wp_postmeta.post_id )
    WHERE 1=1 AND (
    wp_term_relationships.term_taxonomy_id IN (41)
    ) AND (((wp_posts.post_title LIKE ‘%%’) OR (wp_posts.post_content LIKE ‘% %’)))
    AND
    (
    (wp_postmeta.meta_key = ‘map-state’ AND CAST(wp_postmeta.meta_value AS CHAR) = ‘Cork’ )
    OR
    ( wp_postmeta.meta_key = ‘map-city’ AND CAST(wp_postmeta.meta_value AS CHAR) = ‘Youghal’ )
    OR
    ( wp_postmeta.meta_key = ‘search_pubs’ AND CAST(wp_postmeta.meta_value AS CHAR) LIKE ‘%\”Wheelchair Access\”%’ )
    )
    AND wp_posts.post_type = ‘listing_type’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title , wp_posts.post_date DESC LIMIT 0, 10

    As you can see it uses OR instead of AND so i get results for all listings for Cork or Cork City or Wheelchair

    So my question is how do i get the search to work for Cork And Cork City And Wheelchair

    My advanced search will never change so i dont mind if i have to edit core files but cant figure out where i can override or modify the sql

    Thanks

    July 15, 2015 at 4:02 pm
  • Brian Scoby
    0 points
    Beginner
    Members Only Content

    This reply is for PremiumPress customers only.

    Login Now
    July 16, 2015 at 6:51 pm

477

Views

1

Replies