So Very Posh

Thanks for visiting! This is the weblog of Lynda, a 26 year old girl living in Atlanta with her husband, three cats and two cockatiels.


Most Recent Searches


I got this idea from a thread on the forum.  I recently added “Most Recent Searches” performed by other people on my Search Page and I might even add it to the sidebar.  It’s quite simple to do with the wonderfully powerful query module in EE.

Here’s the code I’m using:

{exp:query sql="SELECT * FROM exp_search order by search_date desc limit 10"}
<a href="{path=search/results}{search_id}">{keywords}</a> ({total_results} Results)<br />
{/exp:query}

Simple, isn’t it?  This will link to the actual search.  You can change your path if needed and the limit for how many searches you’d like to pull up.  You can add the date, but that would require some PHP to decode the timestamp.

Additionally, you can include member information if you wish, however this will only pull up results that MEMBERS have searched for, not guests!

{exp:query sql="SELECT * FROM exp_search, exp_members where exp_search.member_id = exp_members.member_id order by exp_search.search_date desc limit 10"}
<a href="{path=search/results}{search_id}">{keywords}</a> ({total_results} Results) by {screen_name}<br />
{/exp:query}



Comments

Comments are closed for this entry

Thanks for that.  I had been playing around with adding that back to my site, but your solution was so much better and usabable than mine.

Posted by Doc on 06/02 at 08:46 AM | Link

woo!  fun!  wink

Posted by julie on 06/02 at 09:17 AM | Link

Is it normal that when a new search is performed the last search info is erased?  that seemed to happen when I first put it up, but I don’t know if it will replicate it now.  (this is a great plugin - thanks smile )

Posted by luka on 06/02 at 10:39 AM | Link

If you’re limiting your results, then the last search will be erased when a new search is performed.  If you’re not limiting your results, this shouldn’t happen.  I’m not sure how many searches EE is set to keep, but if it only keeps a certain number (say 20) then the oldest will be removed also.

Posted by Lynda on 06/02 at 10:51 AM | Link

Very nice! Would you mind if I posted it on pMachineHowto - giving you credit, of course.

Posted by Sue on 06/02 at 11:23 AM | Link

Of course.  The more exposure the better.  smile

Posted by Lynda on 06/02 at 11:33 AM | Link

{exp:query sql="SELECT * FROM ee_search order by search_date desc limit 10"}
<a href="{path=search/results}{search_id}">{keywords}</a> ( {total_results} result<? $results = "{total_results}"; if ($results != "1") { ?>s<? } ?> )<br />
{/exp:query}

Works for displaying the correct form of the word result (ie ‘1 result’ or ‘6 results’wink. Thanks for the start of the code, Lynda.

Posted by Jenna on 06/02 at 08:38 PM | Link

I am using this but altering the “limit 10” has no effect.  With or without it and irrespective of it’s value, only a single search term is returned.  Any thoughts what I am doing wrong?

Posted by Patch on 09/06 at 01:26 AM | Link

It’s quite possible only one search term is available.  Try doing some searches to see if additional results show up.  EE only keeps the search results for a limited time I believe, although I’m not sure how long that period of time is.  So you might not always have the full results available to display.

Posted by Lynda on 09/06 at 06:38 AM | Link

You don’t need PHP in order to render the timestamp. You can do it in SQL.

Posted by Doug on 03/19 at 06:36 PM | Link