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.

Search Multiple fields

June 01, 2011 10:07am

Subscribe [3]
  • #1 / Jun 01, 2011 10:07am

    iPixel

    64 posts

    Hi there, i have a simple search ee-weblog “query” that returns entries based on search criteria…(code below)

    {exp:weblog:entries weblog="calendar" sort="asc" status="Open|Featured" 
    show_future_entries="yes" 
    limit="10" 
    start_on="{current_time format='%Y-%m-%d 00:00'}"
    search:calendar_location="{segment_3}" 
    dynamic="off"}
    
    <?php //code stuff here ?>
    
    {/exp:weblog:entries}

    As you see the search criteria is calendar_location field for the entries has to be {segment_3}‘s value. This works just fine, however i need to also compare {segment_3}‘s value to calendar_location2. search:calendar_location2=”{segment_3}” but when i place them together like so (below) it doesnt work at all, returning odd data as if only 1 search worked but not the other in random order.

    {exp:weblog:entries weblog="calendar" sort="asc" status="Open|Featured" 
    show_future_entries="yes" 
    limit="10" 
    start_on="{current_time format='%Y-%m-%d 00:00'}"
    search:calendar_location="{segment_3}" 
    search:calendar_location2="{segment_3}" 
    dynamic="off"}
    
    <?php //code stuff here ?>
    
    {/exp:weblog:entries}

    Can someone point me in the right direction as to how i can achieve this. In SQL Terms it would should be something like… SELECT * FROM tablename WHERE calendar_location = ‘{segment_3}’ OR calendar_location2 = ‘{segment_3}’;

    THANKS !

  • #2 / Jun 01, 2011 10:40am

    Kernon

    173 posts

    According to a comment added to the documentation, “Multiple SEARCH parameters work as an AND statement” not an OR, which is what you want.  I know, not much help, but at least you know that this particular approach isn’t going to work for you.

    The comment is located here: doc comment.

  • #3 / Jun 01, 2011 10:40am

    iPixel

    64 posts

    Update : The reason this isnt working for me is because by using 2 searches, the “query” automatically uses AND instead of OR, so it tries to find calendar_location = {segment_3} AND calendar_location2 = {segment_3} which does not exist…, is there a way to say search where field = ____ OR ____ ?

    —- ah just saw the post above. Does anyone have any idea outside of useing the ee query module on how to achieve the OR?


    —- just found this plugin/addon, seems like it might do the job. http://ellislab.com/forums/viewthread/130518/

  • #4 / Jun 01, 2011 4:13pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Kernon.

    iPixel, give the plugin a try to see if it works, and let us know what you find out.

  • #5 / Jun 01, 2011 4:34pm

    iPixel

    64 posts

    Yes the plugin works, however it causes the page to load a bit slower than i like so i’m looking into using the ee query module, although that’s giving me a whole bucket of other issues.

  • #6 / Jun 02, 2011 12:09pm

    Kevin Smith

    4784 posts

    Hi iPixel—

    It doesn’t look like there’s a way to get the weblog entries tag to perform the searches using OR instead of AND, so unfortunately, this is one of those times where a custom query will be necessary.

    Kevin

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

ExpressionEngine News!

#eecms, #events, #releases