Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: etc_search: when the default search is not enough
Hello,
currently, it works like this:
- create (in admin
etc_search
tab) anarticle
-type search form withquery
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2}
- assuming the above form has
id=1
, create (in your page form) the following search input form:
<txp:etc_search id="1" label="Custom_1 between" format="{min}..{max}">
<input name="q" type="hidden" value="1" /><!-- to trigger if_search -->
<select name="min">
<option value="0" selected="selected">Choose min value ...</option>
<option value="2000">2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<select name="max">
<option value="10000" selected="selected">Choose max value ...</option>
<option value="2000">2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<input type="submit" />
</txp:etc_search>
- replace
<txp:article />
with<txp:etc_search_results />
in theif_search
part of your page form.
Quickly tested, it should work, but don’t hesitate about feedback/tuning.
Offline
#38 2014-05-13 15:53:31
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Thanks for the help. It looks like it works :-)
One more question (hopefully), is there a way to sort the search results according to custom_1?
Offline
Re: etc_search: when the default search is not enough
element wrote #280779:
One more question (hopefully), is there a way to sort the search results according to custom_1?
Yes, by adding ORDER BY custom_1
(ASC
or DESC
) to query
:
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} ORDER BY custom_1
You can also add additional WHERE
conditions if necessary:
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} AND Section='products' ORDER BY custom_1
Last edited by etc (2014-05-13 16:02:30)
Offline
#40 2014-05-13 16:18:26
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Right, didn’t think about it. Thanks.
I had to add +0 to sort them properly.
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} ORDER BY custom_1+0
Offline
Offline
#42 2014-05-13 16:51:36
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
It works on a PHP 5.3 server, not on a PHP 5.2 server.
Damn, I tried the solution in this post. I replaced the line 392, added the function and the plugin installs but the search on the website doesn’t work.
I get this when I use the search: Fatal error: Call to undefined function safe_escape() in /home/xxxx/public_html/textpattern/lib/txplib_misc.php(653) : eval()’d code on line 421
Offline
Re: etc_search: when the default search is not enough
Ah yes, sorry, safe_escape()
has been introduced in 4.5.0
. You can replace the line
$params['q'] = safe_escape($params['q']);
with
global $DB;
$params['q'] = mysql_real_escape_string($params['q'], $DB->link);
in the plugin code.
Edit: though this function will be depreciated in future PHP versions.
Last edited by etc (2014-05-13 17:26:55)
Offline
#44 2014-05-13 17:39:12
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Thanks, etc. You’re awesome. It works!
Offline
Re: etc_search: when the default search is not enough
Offline
Offline
#47 2014-08-07 14:03:26
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
I’m using this code to search between 2 integer values (min and max).
<txp:etc_search id="1" label="Custom_1 between" format="{min}..{max}">
<input name="q" type="hidden" value="1" /><!-- to trigger if_search -->
...
</txp:etc_search>
<txp:search_term /> always shows the value 1. How do I get the 2 integers to show up on my page as search terms?
Last edited by element (2014-08-07 14:07:11)
Offline
Re: etc_search: when the default search is not enough
element wrote #282714:
<txp:search_term />
always shows the value 1. How do I get the 2 integers to show up on my page as search terms?
Yes, it merely outputs the value of q
input, which is 1
in your case. There is currently no <txp:etc_search_term />
, but I will think about it. For the moment, the simplest option is to replace <txp:search_term />
with
<txp:php>
echo intval(gps('min')).' and '.intval(gps('max'));
</txp:php>
Offline