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.
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:
http://downloads.wordpress.org/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.
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.
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.
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.
I am still waiting for Dave’s answer @colibry.
i solved the problem with woocommerce predictive search .