You are here:  » Clickable custom field to show results

Support Forum



Clickable custom field to show results

Submitted by paddyman on Tue, 2013-10-29 13:22 in

Hi David,

A have a custom field called Author, which I would like visitors to be able to click on each product which would bring them to all results for that Author. Has this been discussed on the forum before? Have searched but mightn't be searching for the right thing !!!!

Thanks

Adrian

Submitted by support on Tue, 2013-10-29 13:56

Hi Adrian,

2 parts to this. Firstly, a new search operator for the custom field needs to be added. To do this, in pto_search.php look for the following code at line 105:

    case "brand":
      $fields = array("merchant","category","brand");

,...and REPLACE with:

    case "brand":
    case "author":
      $fields = array("merchant","category","brand","author");

Your site will then support a search for author:Author Name.

The remaining part can be applied in the templates, so wherever you're using:

%DB_author%

...you could use:

<a href='/shopping?pto_q=author:%DB_author%'>%DB_author%</a>

(adjust accordingly if you're not using /shopping as your container permalink)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Tue, 2013-10-29 14:10

Brilliant, Love it :)

In relation to this, is there anyway to include the author field to be searched from within the search form ?

Thanks again

Adrian

Submitted by support on Tue, 2013-10-29 14:18

Sure - firstly, disable the full text index from wp-admin > Settings > PriceTapestry.org by scrolling down to the External settings and selecting FALSE from the drop-down box alongside $config_useFullText.

Then, in pto_search.php look for the following code at line 200:

  $where .= "search_name LIKE '%".$wpdb->escape($word)."%'";

...and REPLACE with:

  $where .= "search_name LIKE '%".$wpdb->escape($word)."%'";
  $where .= " OR author LIKE '%".$wpdb->escape($word)."%'";

Have a play with the results and check for relevancy - many users building niche sites as I know you are in this case find better results without full text search anyway, but if you think they could be improved let me know and a compound full text index including author can be added easily.

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Tue, 2013-10-29 14:40

Works great :)

Many thanks !!!!

Adrian

Submitted by paddyman on Sun, 2013-11-03 21:53

Hi David,

Just one more thing on this...

When I click on the author field with an author such as Tim O'Brien, search only goes to ?pto_q=author:Tim%20O

I modified PTO.php to include the ' character, but still no joy

$pto_q = (isset($pto_q)?pto_common_normalise(urldecode($pto_q),":\'."):"");

Any ideas?

Thanks

Adrian

Submitted by support on Mon, 2013-11-04 08:44

Hello Adrian,

As the placeholder is being used within a URL area it would need to be urlencode() as the apostrophe is breaking the HTML markup, so I think the best thing to would be to create a new placeholder style %DBU_fieldname%. To do this, assuming that you're using the placeholder on the Product / Main template, in pto_product.php look for the following code at line 499:

    $html .= $html_product;

...and REPLACE with:

    if (strpos($html_product,"%DBU_"))
    {
      preg_match_all('/%DBU_(.*)%/U',$html_product,$matches);
      foreach($matches[1] as $field)
      {
        $html_product =
          str_replace("%DBU_".$field."%",urlencode($product->$field),$html_product);
      }
    }
    $html .= $html_product;

And then in your template, use %DBU_author% in place of %DB_author%

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Mon, 2013-11-04 14:47

Hi David,

Author is appearing as %DBU_author% on the product page. I've emailed you a few files if you wouldn't mind taking a look.

Thanks

Adrian