• Resolved bcimedia

    (@bcimedia)


    We’ve got two dropdowns in our search, and they work like a dream. But there are 1600+ categories, and they are not listed by alphabetical order in the dropdown. They really need to be, and as it is, it’s causing a poor user experience. I’ve looked everywhere in the docs and the knowledge base and there is nothing on how to change the sort. There is a mention of the sort, but nothing linking to how the sort is defined by default and/or how to change it. Can you help with this please? I feel like it’s something easy.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    How have you created those dropdowns? It depends on that. If you are using wp_category_dropdown(), it takes the orderby parameter which defines the order (and the default setting is ordering by term ID, not by title). You can set the orderby parameter to name to an alphabetical sorting.

    Thread Starter bcimedia

    (@bcimedia)

    I created the dropdowns using your shortcode parameters:

    [searchform post_types=”yellow-pages” dropdown_1=”yellow-pages-locations” dropdown_2=”yellow-pages-categories”]

    Works great, but I don’t know the other parameters to sort the dropdowns by alpha. I’d also like to change the placeholder for the search bar from “Search…” to “Keyword” but I have been unsuccessful in all my attempts. Your documentation doesn’t give me the parameters for these items. Or maybe I’ve missed it?

    Plugin Author Mikko Saari

    (@msaari)

    Yeah, you can’t change the order parameter from that. I probably need to do something about that; I haven’t noticed the default value is not order by name, that would be the best. Or WP has changed it, that’s also possible. I’ll see what can be done about it; it may require a Relevanssi update.

    The search form placeholder comes either from your theme (searchform.php file) or WordPress. Relevanssi doesn’t define it; Relevanssi just takes the default search form and adds extra stuff to it. If your theme has a searchform.php file, you can edit to change this.

    If it doesn’t have, you can use the relevanssi_search_form filter hook to change this. It gives you the full HTML code of the search form and you can modify it as much as you want (you could also sort the dropdown values with it, actually). Simple search and replace of “Search…” with “Keyword” should do the trick:

    add_filter( 'relevanssi_search_form', function( $html ) {
      return str_replace( 'Search...', 'Keyword', $html );
    } );
    Thread Starter bcimedia

    (@bcimedia)

    So I think I tried this filter before, and it didn’t work. And that’s what baffled me. I just now entered this into my theme’s functions.php file, and it didn’t change a thing. That’s what I just can’t figure out. My theme doesn’t have a searchform.php file, so I’m guessing it’s taking it from the WordPress core.

    What would be the filter code to change the sort on the dropdowns? I have no idea. Thanks!

    Plugin Author Mikko Saari

    (@msaari)

    You have to spell it exactly as it is in the search form, try this:

    add_filter( 'relevanssi_search_form', function( $html ) {
      return str_replace( 'Search …', 'Keyword', $html );
    } );

    As for the value sorting, you can just copy the latest /lib/shortcodes.php from the Github repo to get the fix before the new version is released.

    Thread Starter bcimedia

    (@bcimedia)

    Excellent, thanks!!

    Thread Starter bcimedia

    (@bcimedia)

    closing, everything works great. Thank you !!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to change sort on dropdowns’ is closed to new replies.