WordPress.org

Ready to get started?Download WordPress

Forums

SimpleMap Store Locator
Selecting multiple categories doesn't show results (6 posts)

  1. flymke
    Member
    Posted 2 years ago #

    Hi, I am using Simplemaps version 2.4.4.1, WordPress 3.3.1.

    I added 2 locations and assigned them each to their own category. If I select 1 it brings results on the map, but if I select both it doesn't come up with anything.

    I narrowed down the problem to the Inner Join SQL statement, in xml-search.php, line 81-85:

    INNER JOIN
    $wpdb->term_taxonomy AS tax_$i ON
    term_rel_$i.term_taxonomy_id = tax_$i.term_taxonomy_id
    AND tax_$i.taxonomy = '$taxonomy'
    AND tax_$i.term_id $search_value

    which generates this query when I select both categories:

    SELECT
    lat_tbl.meta_value AS lat,
    lng_tbl.meta_value AS lng,
    ( 3959 * ACOS( COS( RADIANS('48.1127929') ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS('11.568187200000011') ) + SIN( RADIANS('48.1127929') ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance,
    posts.ID,
    posts.post_content,
    posts.post_title
    FROM
    wp_posts AS posts
    INNER JOIN
    wp_postmeta lat_tbl ON lat_tbl.post_id = posts.ID AND lat_tbl.meta_key = 'location_lat'
    INNER JOIN
    wp_postmeta lng_tbl ON lng_tbl.post_id = posts.ID AND lng_tbl.meta_key = 'location_lng'
    
    INNER JOIN
    wp_term_relationships AS term_rel_1 ON posts.ID = term_rel_1.object_id
    INNER JOIN
    wp_term_taxonomy AS tax_1 ON
    term_rel_1.term_taxonomy_id = tax_1.term_taxonomy_id
    AND tax_1.taxonomy = 'sm-category'
    AND tax_1.term_id = 16
    
    INNER JOIN
    wp_term_relationships AS term_rel_2 ON posts.ID = term_rel_2.object_id
    INNER JOIN
    wp_term_taxonomy AS tax_2 ON
    term_rel_2.term_taxonomy_id = tax_2.term_taxonomy_id
    AND tax_2.taxonomy = 'sm-category'
    AND tax_2.term_id = 17
    
    WHERE
    posts.post_type = 'sm-location'
    AND posts.post_status = 'publish'
    GROUP BY
    posts.ID
    HAVING distance < 31
    
    ORDER BY
    distance,  posts.post_name ASC
    LIMIT 20

    I did some QA with the database, but I am not sure where exactly the problem lies. If I leave the inner joins out, the results are working just fine (but of course there's then trouble when I only select one category).

    Any hints?

    Thanks, flymke

    http://wordpress.org/extend/plugins/simplemap/

  2. jyup0116
    Member
    Posted 2 years ago #

    did you figure that out?
    I have same issue.
    any one knows the way this?

  3. flymke
    Member
    Posted 2 years ago #

    Actually no. I worked around it:

    <script type="text/javascript">
    $(document).ready(function() {
    // Workaround for Simplemap Bug
    $("#location_search_sm-category_fields input").click(function() {
      $("#location_search_sm-category_fields input").each(function() {
      	$(this).attr('checked', false);
      });
      $(this).attr('checked', true);
    });
    });
    </script>

    So you can only check once a time.. Not pretty but was enough for my needs actually.

  4. jyup0116
    Member
    Posted 2 years ago #

    Thanks for your sharing.
    Actually, that's better solution to me too.
    then where do I have to include that script?

    thank you, flymke, again for your sharing.

    JK

  5. flymke
    Member
    Posted 1 year ago #

    No problem, you can put it in the header.php before <body>. You also need to include jquery if you don't have it (usually you do, but anyway). See if you have the same selectors (#location_search_sm-category_fields input) for the checkboxes.

    Like so:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    // Workaround for Simplemap Bug
    $("#location_search_sm-category_fields input").click(function() {
      $("#location_search_sm-category_fields input").each(function() {
      	$(this).attr('checked', false);
      });
      $(this).attr('checked', true);
    });
    });
    </script>
    <body>
    <!-- ... -->

    Hope that helps!

  6. Victoria
    Member
    Posted 1 year ago #

    Thank you so much for sharing!
    had same issue and works good!! :D

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic