• Resolved Traction

    (@tractionokc)


    Does a function exist where, if a category is defined, it shows that location before locations that do no have a category?

    I’m trying to give certain locations weight so the default ‘orderby’ shows specific locations first regardless of distance but still within the defined search radius.

    This, of course, being on the front end not the admin area.

    Thanks!

    https://www.ads-software.com/plugins/wp-store-locator/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    Sorry for the late response, I somehow overlooked it.

    What you want doesn’t exist yet, but if you are comfortable with code then I can point you in the right direction how to make it work?

    Thread Starter Traction

    (@tractionokc)

    Yes, please do!

    Plugin Author Tijmen Smit

    (@tijmensmit)

    So the first problem is that by default no data is returned saying which category a location is assigned to. You can fix this by adding code like this to the functions.php in your theme folder. It uses the wpsl_store_meta filter, which allows you to include custom data for each location.

    This code will only include the first term name, if you want to know all the term names you will have to loop over the $terms and grab all the term names.

    Once all the location is collected, you can modify it with the wpsl_store_data filter ( no documentation yet ). What you can do is go through the collected data and use array_multisort to sort the results alphabetically by category name.

    This doesn’t work perfect in this case, because when it does the sorting it will place locations with empty terms above locations that do have terms set.

    I think there are two ways to fix this issue. One of them is to set the default $store_meta[‘terms’] = ”; always to ‘x’, so when the alphabetical sorting is done they will always end up at the bottom. But this will mess with the distance ordering.

    Another fix would be to loop over the results again, create two arrays with one holding the locations with the categories set, and the other one with the empty categories. Then merge them together, but make sure the one that does have the categories set is placed before the array holding the locations with no categories.

    Thread Starter Traction

    (@tractionokc)

    Looks like it works like a charm! I’m only using 2 categories which happen to be alphabetical in the way they need to be ordered on the front-end.

    Thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Locations by Category’ is closed to new replies.