7

this doesn't seem to work, since you can only "search" in custom fields:

{exp:channel:entries channel="#" search:title="foo"}

Is there any way to easily achieve this ? Preferably without adding any custom fields or using advanced search add-ons.

5 Answers 5

9

You're correct that the native search:field_name param only works on custom fields and not titles, annoyingly, so we do need an addon to do this.

Stash is overkill for this use case though and requires a lot of code to get the (fairly simple) job done.

I'd use another fine Croxton product instead: the Search Fields Plugin, just wrap it around your {exp:channel:entries} tag:

{exp:search_fields 
    search:title="keyword" 
    channel="my_channel" 
    parse="inward"}
    {exp:channel:entries entry_id="{search_results}" disable="member_data|categories" dynamic="no" orderby="title" sort="asc" limit="10"}
        <a href="{page_url}">{title}</a>
    {/exp:channel:entries}
{/exp:search_fields}
2
  • perfect, exactly what I was looking for. Thanks man.
    – janvl
    Nov 29, 2012 at 13:14
  • 1
    Very cool - did not know about this addon.
    – CreateSean
    Nov 29, 2012 at 17:24
3

I'd just use the query module:

{exp:query sql="SELECT entry_id FROM exp_channel_titles WHERE title LIKE '%searchterm%' and weblog_id='1' " backspace="1"}{entry_id}|{/exp:query}

That would pull a list of entry_ids for a given channel, that you could then use in a channel:entries tag or where ever else you needed it.

Stash would work but would pull a lot more data that was then just discarded, and this approach works with a base EE install.

2

You could use Title Master or MX Title Control to create a custom title field that could then be searched. This has a couple other benefits for the client UX by having them enter information only once in the publish form and can break apart things like management team names that can then be sorted by last name, etc. I've had some trouble with Structure and Title Master (who hasn't had SOME trouble with Structure?) but if you're not using Structure or your channel title isn't tied to your URL title directly then this should't be an issue. Haven't tried MX Title Control in a long time but the support forum does note some quirks with it as well.

Update: An update to Title Master makes my comment above moot. The two play nicely together again.

0
1

Seems like there should be an obvious answer but that being said, I'd use stash:

//Open up a stash list
{exp:stash:set_list parse_tags="yes" name="my_entries"}
//Open up your channel
{exp:channel:entries channel="#" disable="Whatever"}
//Capture the entry title
{stash:entry_title}{title}{/stash:entry_title}
//Maybe even a description
{stash:entry_desc}{desc}{/stash:entry_desc}
{/exp:channel:entries}
//Close stash
{exp:stash:set_list}

//Now display the results matching a regex string to the entry title
{exp:stash:get_list name="my_entries" match=[#foo#] against="entry_title"}
{entry_title}//Display the title of any results
{entry_desc}// And the description or any other value(s) caught initially
{/exp:stash:get_list}

I haven't looked at the EE docs for a while but using Stash alot lately and this should work.

0

Thank you for this! I was looking for a solution for the end user to enter a keyword into a custom field and display related entries and searched everywhere. This works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.