You are here:  » Sort Search result by price (low to High)


Sort Search result by price (low to High)

Submitted by fstore on Tue, 2012-07-24 12:17 in

Hi David

I posted this quested earlier on pricetapestry.com by mistake... It is more relevant to wordpress plugin forum.

I wanted to know how can i change the default sorting order of search results?
currently mine is setup to sort the results based on relevance , i wanted to change it to price (low to high)

Thnaks in advance..

Regards
Hassan

Submitted by support on Tue, 2012-07-24 16:49

Hi Hassan,

It's defaulted at line 360 in pto.php:

  $pto_sort = (isset($pto_sort)?$pto_sort:"relevance");

...simply replace relevance in that line with the default sort required; e.g. priceAsc

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sat, 2012-07-28 14:04

Thanks David
Is there anyway to highlight the selected sort method (e.g. text on the search form). So site visitor can see which sort method is enabled?

I have three sort methods (relevance, low price, high price) available to choose from on search result page. I have set "low price to be a default. I want to change the text properties (e.g. highlight, or underline the font etc) of the enable sort method? so that site visitor can see the how the search is being sorted.

Regards
Hassan

Submitted by support on Sat, 2012-07-28 17:11

Hello Hassan,

Without having to create a complex %IF_SORT...% set-up; you can hard-code a simple solution to wrap the selected sort text within a <span> so that you can style the selected sort individually.

In pto_search.php look for the following line at the end of the pto_search_banner() function at line 368:

  return $html;

...and REPLACE with:

  global $pto_sort;
  $search["relevance"] = "Relevance";
  $search["priceAsc"] = "Low to High";
  $search["priceAsc"] = "High to Low";
  $html = str_replace($search[$pto_sort],"<span class='activeSort'>".$search[$pto_sort]."</span>",$html);
  return $html;

If you've changed the text used in your wp-admin > Settings > PriceTapestry.org template for Search / Banner change the equivalent text in the $search array....

Finally, in your CSS (resources/pto.css) add the following class to define .activeSort as required; e.g.

.activeSort {
  text-decoration: underline;
}

Don't forget to do a hard refresh in your browser (CTRL+F5) after changing CSS to ensure that all resources are reloaded...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2012-07-29 14:00

Thanks it worked perfectly.