• Hi Dave/all,

    I am using your plugin with Relevanssi without any problem.

    1. Is it possible to change the output of the search result so that instead the results being wrapped in <li>, they are wrapped in <a> and the whole result is clickable without modifying the core files?

    2. I also want to include two custom field values below the title which I am able to achieve using the filter ‘dwls_post_title’, but it makes them also clickable and part of the title.

    3. Instead of “View more results”, I want to display “See all results for search_text ?”.

    Please let me know if these are possible and how.

    Thanks

    https://www.ads-software.com/extend/plugins/daves-wordpress-live-search/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Dana Ross

    (@csixty4)

    1. There isn’t a way at the moment, but maybe I can use some kind of lightweight Javascript templating system to do it. There hasn’t been much demand, but I’ve been wanting to do something with that block of code that concatenates strings to make HTML. That’s a little too old-school for production code these days. There is a jQuery click handler in the code, though, that makes the whole result clickable already.

    2. Yeah, that would be another good case for a templating system of some kind. I could have a hook for adding custom fields on the back end, and load a custom template on the front end that uses those fields. I might have some down time next week to look into it. It would help simplify the plugin’s Javascript, too, and I’m always thrilled to end the day with less code than when I started.

    3. You might be able to do this with Javascript, putting your own text in DavesWordPressLiveSearchConfig.viewMoreText after the page loads. I haven’t tried it, but it should work. The other option I can think of is to create your own language file, but that’s going to get overwritten the next time you update. Give the Javascript approach a try.

    Plugin Author Dana Ross

    (@csixty4)

    That’ll teach me to look at support questions before bed.

    Looks like the next version of the plugin is going to be v4.0 because of big changes, including templating. WordPress already ships with Underscore.js, which means I can count on there being a template library present anyway.

    You can grab a copy of the latest “trunk” at this URL if you want to play around with it:
    https://downloads.www.ads-software.com/plugin/daves-wordpress-live-search.zip

    The results template is in js/dwls-results.tpl — I don’t like having so much logic in there, but I guess it’s not the end of the world. I might tweak it as I get closer to release.

    There’s a new filter called “dwls_alter_result_template” that gets passed the contents of the template file as a string and expects a string back with a replacement template’s HTML. You can use this to inject your own template.

    I don’t think it’s production-worthy yet, but if you want to give it a try & see how it would work for you that would be great.

    Plugin Author Dana Ross

    (@csixty4)

    Also added a filter called “dwls_post_custom” to add your own custom fields to the search result $post before it’s sent to the browser. You can use this for your custom field values & then reference them in the template.

    Thread Starter bekar09

    (@bekar09)

    Hi Dave,

    Thanks for your reply and flexibility to add these functionalities. I did not get a chance to test all of these. What I tested is the js/dwls-results.tpl and currently it breaks the View more results link. The html that is generated is below:

    <a href="' + DavesWordPressLiveSearchConfig.blogURL + '/?s=' + resultsSearchTerm + '">View more results</a>

    Also the code for View more Results is written inside the “_.each” (foreach) block.

    <% if(searchResult.show_more !== undefined && searchResult.show_more && DavesWordPressLiveSearchConfig.showMoreResultsLink == "true") { %>
                    <div class="clearfix search_footer"><a href="' + DavesWordPressLiveSearchConfig.blogURL + '/?s=' + resultsSearchTerm + '"><%= DavesWordPressLiveSearchConfig.viewMoreText %></a></div>
            <% } %>

    This causes the link to be rendered along with each result. I am reporting these so that you can fix it before launch.

    I will test the two filters and report back.

    Thread Starter bekar09

    (@bekar09)

    Hi Dave,

    Can you give two example uses of the filters?

    Also wanted to report that the search has become incredibly slow in this version.

    Thanks.

    Hi, i still try to make the search results to be the name of the products from woocommerce but no way to finish this job:( maybe can tell me a solution guys ty.

    Thread Starter bekar09

    (@bekar09)

    I am still waiting for Dave’s answer @colibry.

    i solved the problem with woocommerce predictive search .

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Customize search result output’ is closed to new replies.