You are here:  » Wordpress plugin - customising search shortcode?


Wordpress plugin - customising search shortcode?

Submitted by lowndsy on Wed, 2021-09-01 14:39 in

I have just rebuilt my old PT ink website using PT and the PT Wordpress plugin.

The old PT site accepted a comma delimited list of ink cartridges and just returned all the results that matched.

I can't get the PTO search plugin to work like that - it only searches for the first result. I can supply it as space delimited as well, didn't seem to make any difference to my tests.

I have tried changing the "fulltext search" and "search description" settings but it didn't seem to make any difference.

I found the search function in the plugin folder and I can see the PHP that drives the search.
I sort of follow how it builds the SQL statement, but it's pretty complex and I know I'll mess it up.

Does anyone know the bits to change to get search to acccept a comma delimited list of search criteria?

In an ideal world I'd clone the PTO search shortcode so I can still use the existing search and a second modified version with different shortcode.

Thanks,
Steve

Submitted by support on Thu, 2021-09-02 09:43

Hi Steve,

A basic search with logic OR instead of AND might work best in this case. To try this, first make sure $config_useFullText is set to FALSE in the plugin configuration (wp-admin > Settings > PriceTapestry.org) and then edit pto_search.php and look for the following code at line 249:

        $where = implode(" AND ",$wheres);

...and REPLACE with:

        $where = implode(" OR ",$wheres);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by lowndsy on Thu, 2021-09-02 11:45

Thanks David, I knew it would be easy for you! That works really well and my site is much more complete now.

I'm using a comma delimited list with no spaces. If a space ever sneaks in will that make a difference or does it get trimmed?

Got a couple more questions - hope you don't mind.

How do I implement paging? I found the setting to change the amount of results per page, but I'm not getting the nav to jump to page 2. Do I need to add something to my template or is there a setting I missed?

When there is no search result I want to just plonk a link to an Amazon search - loads of ink there.
I have found the bit in the PT settings where you change the default text, but it doesn't accept any wildcards. Any idea how I'd use a value like the page title or the search string in that box?

Thanks,
Steve

Submitted by lowndsy on Thu, 2021-09-02 12:24

It looked like that was working, but now I'm getting some very odd results.

For example this page: {link saved}

Here is the shortcode:

[pto search="HP-3R-25/26,HP-5R-25/26,RI-51626A,RI-51625A"]

the results don't match any of those 4 strings. I have "search in description" turned off at the moment.

could it delimiting by other values like the / and hyphen too?

Submitted by support on Fri, 2021-09-03 09:27

Hi Steve,

The basic search method would require space separation between the keywords...

Cheers,
David.
--
PriceTapestry.com

Submitted by lowndsy on Fri, 2021-09-03 09:55

It's not the delimiting that is the problem as such, though I can easily switch to spaces instead of commas.

Some of the ink cartridge serial numbers have characters like / and - in the middle, and PT is replacing them with extra spaces which throws the results off completely.

Any idea how to stop that?

Submitted by support on Fri, 2021-09-03 11:01

Hi,

Ah yes those characters would be removed by the normalisation of the query but you can remove that - if you edit pto.php and look for the following code at line 500:

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

...and REPLACE with:

  $pto_q = (isset($pto_q)?$pto_q:"");

Cheers,
David.
--
PriceTapestry.com

Submitted by lowndsy on Fri, 2021-09-03 12:26

Thanks David. I just popped that in but mu first try forced a 500 error on the entire site. It seemed to work with a question mark after the isset() - does that seem reasonable?

$pto_q = (isset($pto_q)?$pto_q:"");

I think I'm getting there now. Any idea what I'm doing wrong re paging? And getting the search string to appear in the "no results" string?

Thanks,
Steve

Submitted by support on Sat, 2021-09-04 09:59

Hi Steve,

That's the correct change to the code (corrected above).

To have the pagination show below search results generated from a shortcode, edit pto.php and look for the following code at line 826:

          $html .= pto_search();

...and REPLACE with:

          $html .= pto_search();
          $html .= pto_search_navigation();

To include the search term in the no results message; edit pto_search.php and look for the following code at line 430:

    $html = $pto_html_search_noresults;

...and REPLACE with:

    global $pto_q;
    $html = "No results for ".$pto_q;

...or as required.

Cheers,
David.
--
PriceTapestry.com