By bnubbz on
I know how to successfully use arguments in drupal's views module, but when it "filters" based on those arguments it uses "=" in the where clause of the SQL statement. However, I would like to use "like" instead of "=" in the where clause of the SQL statement so I can pass in, say the title of a node, as an argument and then show all nodes that CONTAIN the title passed in. I am not interested in grabbing only the nodes where the title is exactly the same as the title passed in. Does anyone know how I can do this? Is this possible?
Comments
=-=
I don't know if it's possible without a custom views module or some code added to vies but if you tag the thread with the version of drupal in use so someone who may have an answer can tell whether you require something for Views1 (D5) or Views2 (D6) as the two are very different under the hood.
Feel free to edit your node : )
Thanks for the tip, I tagged
Thanks for the tip, I tagged the thread with the version of drupal I am using.
=-=
If you don't get an answer in the forums here for one reason or another I'd consider filing a support request in the issue queue of views after checking to ensure there aren't other requests for similar information. The subcommunity subscribed to the views.module may be better equipt to handle such a specific request.
I actually created my own
I actually created my own module for this yesterday, but I thought it might be easier to do with views. I might just go with my module instead.
A workaround
I had the same problem and found a quick workaround for it.
You need to modify the query.inc file under /views/includes.
Steps to the solution:
- Open query.inc file
- Find the function 'function condition_sql'
- Replace the block;
if (count($info['clauses']) > 1) {
$clause = '(' . $clause . ')';
}
with the following block;
if (count($info['clauses']) > 1) {
$clause = str_replace(" = '"," LIKE '%%",$clause);
$clause = '(' . $clause . ')';
$clause = str_replace("')","%%')",$clause);
}
As an example;
the query:
'WHERE (field_name = 'search_string')
is converted into:
'WHERE (field_name LIKE '%search_string%')
As a side effect, this modification will affect the complete WHERE clause!! All of your '=' operators that compare string values will eventually be converted into 'LIKE'...!
I hope that this workaround will be useful for people who has the same problem...
Surely
the hook_views_query_alter() will do what is required here without changing core? Not used it but it should suit this purpose exactly.
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy