EEConf 2024 is around the corner! EEConf 2024
Use this plugin to search weblog entry titles, custom fields, category names, category descriptions and category custom fields.
Search parameter syntax is identical to the weblog search parameter.
In addition to entry custom fields you can search entry titles, category names, category descriptions and category custom fields. When searching categories references to category fields should be prefixed with ‘cat_’.
For example: search:cat_name=”keyword” search:cat_description=”keyword” search:cat_custom_field=”keyword”
Returns a delimited list of entry ids.
search:[field] = (optional) Field can be title, cat_name, cat_description, [custom_field_name], cat_[custom_field_name].
weblog = (optional) Single weblog name to search. Default is * (searches all weblogs).
operator = (optional) ‘AND’ or ‘OR’. Operator for joining search field WHERE conditions. Default is ‘OR’.
delimiter = (optional) Delimiter for returned entry id string. Default is pipe |.
placeholder = (optional) Single variable placeholder to replace with search results output. Default is search_results (use as {search_results}).
dynamic_parameters = (optional) Eg: “title|custom_field”. Allow specific search parameters to set via $_POST (form fields should have same name as the fields you wish to search).
This plugin is best used as a tag pair wrapping {exp:weblog:entries}.
{exp:search_fields search:title="keyword" search:custom_field="keyword" search:cat_name="keyword" operator="OR" weblog="my_weblog" parse="inward"}
{exp:weblog:entries entry_id="{search_results}" dynamic="off"}
<a href="http://{page_url}">{title}</a>
{/exp:weblog:entries}
{/exp:search_fields}
Hi Mark,
A really nice neat little addition to all the plugins out there this one so thanks for that 😊
Any ideas how much overhead this applies to a page in getting the entries like this? I mean, having a plugin supplying the entry ids to the weblog tag like this?
Anyhow a really nice little plugin which I’m sure will come in handy when needing to search titles so thanks for the upload.
Best wishes,
Mark
There is a very small additional overhead for searching entry titles (compared to using exp:weblog:entries search:field=”) as I’m using an extra join. Searching category titles and description adds a further two joins, and searching custom category fields another join and a second query. These additional joins are only made as needed, so if you’re just searching titles the overhead is only one join. Narrowing the search using the weblog parameter will help with speed, and using the exp:weblog:entries disable parameter will allow you to reduce the total number of queries, so be sure to do that for features not required.
So this isn’t quite a replacement for the search module, it doesn’t cache results and will probably struggle if you have a very large number of entries; however, it should be fine for custom search forms on sites with a few thousand entries per weblog.
There is a very small additional overhead for searching entry titles (compared to using exp:weblog:entries search:field=”) as I’m using an extra join. Searching category titles and description adds a further two joins, and searching custom category fields another join and a second query. Narrowing the search using the weblog parameter will help with speed, and using the exp:weblog:entries disable parameter will allow you to reduce the total number of queries, so be sure to do that for features not required.
Yep I always add those in as standard anyway 😉 Definitely the best thing to do on any site.
So this isn’t quite a replacement for the search module, it doesn’t cache results and will probably struggle if you have a very large number of entries; however, it should be fine for custom search forms on sites with a few thousand entries per weblog.
Sounds good to me 😊
Thanks again for a great plugin addition. I’m sure many others are going to love this one.
Best wishes,
Mark
This plugin is great, however, any suggestions on how to pass values dynamically to it would be welcome!
For example, I am trying to do this:
{exp:search_fields search:title="<?php echo $_GET['q'] ?>" search:cf_pros_firstname="<?php echo $_GET['q'] ?>" search:cf_pros_lastname="<?php echo $_GET['q'] ?>" operator="OR" weblog="<?php echo $_GET['q'] ?>" parse="inward"}
{exp:weblog:entries entry_id="{search_results}" dynamic="off"}
{title}|{url_title}
{/exp:weblog:entries}
{/exp:search_fields}
… I am trying to use it in conjunction with an ajax auto-complete plugin found here.
I hope that’s all clear 😊
Glad you worked it out. One very important thing I’d suggest though if you’re doing it this way is sanitize the $_GET values before passing them to the script. EE provides the Input class for this. I would also add in some checking to prevent XSS (if you plan on re-displaying the search term):
<?php
global $IN;
$q = str_replace(array('{','}','?','\"','\\'), '', trim($q = $IN->GBL('q', 'GET')));
?>
Alternatively you can use the dynamic_parameters parameter to tell the script to grab the submitted values from the $_POST array, although you would need to duplicate the field values if you’re searching in more than one custom field for the same string.
This is just what I’m looking for. But: when I try to install it, it kills my plugin manager (page is completely blank). According to the knowledge base - http://expressionengine.com/knowledge_base/article/my_admin_plugin_manager_page_is_blank/ - that’s normally due to a PHP parse error or permissions. I’ve set permissions to 777 and still not working, so might there be an error in the code?
Have enabled PHP errors via a .htaccess. Here’s what I got:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webadmin@kundenserver.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
… Is that any use?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.