2

I am using the following tag to get only channel entries with a custom field matching the last URL segment:

{exp:channel:entries search:collection_name="={last_segment}"}

This works fine for most values, but I've found that when the field contains double quotes, no entries are returned.

For example, the following URL segments work, and only the matching entries are shown: Collection, Collection 43

However, this URL doesn't return any entries, even when there are matches in the DB: The "new" collection.

So I need to somehow escape these characters to allow this to work?

  • Can you clarify what you're trying to accomplish with this search? There might be a easier solution. Does that channel entries tag return a single entry? If you're using the {last_segment} variable for a search, this won't work because the {last_segment} variable will have underscores, hyphens, etc. in the variable. – Siebird Feb 5 '13 at 15:04
  • I have a number of entries sorted into collections. These collections are identified by a text field on the channel. I would rather not use categories. I want to be able to display just the channel entries that belong to a specific collection, and have a permalink URL to that collection. – colincameron Feb 5 '13 at 15:08
  • What does the URL structure look like for the ones that work (ie. Collection & Collection 43) vs. the one that doesn't (ie. The "New" Collection). It sounds like this method is prone to user input error, as there is no standardization. – Siebird Feb 5 '13 at 15:11
  • Example URLs: localhost/~colin/ee/index/Collection, localhost/~colin/ee/index/Collection%2043, localhost/~colin/ee/index/The%20%22new%22%20collection. The user wouldn't be entering these URLs - they would be linked to from other pages. – colincameron Feb 5 '13 at 15:18
  • Updated my answer! – Siebird Feb 5 '13 at 15:28
2

Since you have the search parameter variable prefixed with =, it's an exact match. Try removing the prefix.

{exp:channel:entries search:collection_name="{last_segment}"}

Update

The problem is with special characters in the URL. EE strips out uppercase letters, spacing & special characters in the native {url_title} field for proper URL structure. So all the data in the {collection_name} custom field will need to be reformatted so the {last_segment} variable can be used properly in your use case. The "new" collection should really be the-new-collection in the collection name custom field.

However, I would approach this differently with either categories or even use Playa. With Playa, you could create a Collection Channel and then use a Playa field in the other channel to relate each entry to one or more collections. Then use {exp:playa:parents} tag to display all reverse related entries:

{exp:playa:parents channel="other_channel" url_title="{last_segment}"}
| improve this answer | |
  • Thanks, I did try without the = but I need exact matching, otherwise the first search, Collection, would match all three of my examples. I will edit my question to clarify. – colincameron Feb 5 '13 at 14:21
  • Thanks for the update. I think it might be worth investigating whether it is possible to move to using categories. Just a note on special characters - when I put {last_segment} on the page, The "new" collection is printed, correct case and quotes. I think the problem is to do with the quotes not being escaped - when I use single quotes on the channel entries tag, it works perfectly for my examples. – colincameron Feb 5 '13 at 15:33
  • I still recommend a different approach as your collections could get quite messy with different variations of the same name. – Siebird Feb 5 '13 at 15:36
  • The content is automatically imported from another application, so mis-spellings aren't an issue. I will investigate other options though. – colincameron Feb 5 '13 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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