ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Eazy Channel Entries Search Question ?

January 07, 2013 11:03pm

Subscribe [1]
  • #1 / Jan 07, 2013 11:03pm

    Brainwrek

    75 posts

    By default, the following code yields results only if field1 AND field2 contain the keyword.  Wondering if there’s a workaround to yield results if a keyword appears in field1 OR field2 ?

    {exp:channel:entries search:field1="keyword" search:field2="keyword"}
    {title}
    {/exp:channel:entries}
  • #2 / Jan 07, 2013 11:33pm

    Bhashkar Yadav

    727 posts

    Hi Brainwrek,

    It doesn’t seem that you can have desired result with the use of channel entry tag but you can use query module by writing the query like:

    {exp:query sql="SELECT entry_id AS entryID FROM exp_channel_data WHERE (field_id_[id of field1]='keyword' OR field_id_[id of field2]='keyword') AND channel_id='[CHANNEL ID]'" LIMIT="5"}
    {exp:channel:entries entry_id="{entryID}"}
    {title}
    {/exp:channel:entries}
    {/exp:query}

    Hope, it would help you.


    Best Regards,

  • #3 / Jan 08, 2013 12:06am

    Brainwrek

    75 posts

    Splendid, Bhashkar.

    Thank you for the quick solution.  My only concern with your method is that {exp:channel:entries} will be called for each individual entry.  So limit=“20” will call {exp:channel:entries} 20 times.  Seems like a lot of unnecessary overhead. 

    Nevertheless, it may be the only solution, and I thank you again for your help.  😊

  • #4 / Jan 08, 2013 2:16am

    Bhashkar Yadav

    727 posts

    Yes, you are right. We can overcome this issue by updating the query as

    {exp:query sql="SELECT GROUP_CONCAT(CONVERT(entry_id, CHAR(7)) SEPARATOR ‘|’) AS entry_ids FROM exp_channel_data WHERE (field_id_[id of field1]='keyword' OR field_id_[id of field2]='keyword') AND channel_id='[CHANNEL ID]' GROUP BY entry_id LIMIT 1"}
    {exp:channel:entries entry_id="{entry_ids}"}
    {title}
    {/exp:channel:entries}
    {/exp:query}

    In above query {entry_ids} will return entry ids separated with “|” like 1|2|3 so your channel entry tag will be called once.

    I didn’t test above but hope it would work very well.


    Best Regards,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases