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.

Channel Entries search:field_name= parameter comparison

December 25, 2012 6:53am

Subscribe [1]
  • #1 / Dec 25, 2012 6:53am

    okaris

    4 posts

    {exp:channel:entries entry_id_from="0" entry_id_to="{id}" limit="9" orderby="date"  paginate="bottom" search:isgif="no" search:likes=">2500"}

    As you see on the code above I want to receive entries which has the ‘likes’ column value greater than 2500

    Is there any easy way to do this.

    Cheers

  • #2 / Dec 25, 2012 9:28pm

    Bhashkar Yadav

    727 posts

    Hi Okaris,

    The “search” doesn’t work with greater than or less than operators. So the easiest way will be to use if condition within channel entry tag. Like:

    {exp:channel:entries entry_id_from="0" entry_id_to="{id}" limit="9" orderby="date"  paginate="bottom" search:isgif="no"}
    
    {if likes >= 2500} 
    
    [CONTENT TO PUBLISH]
    
    {/if}

     

    Best Regards,

  • #3 / Dec 26, 2012 1:02am

    okaris

    4 posts

    But that would result in overwhelming the database. And eventually can return zero entries. for example if the firsst 9 entries all have likes less than 2500 there would be no return.

    Is there a way to do this with ee sql?

  • #4 / Dec 26, 2012 2:27am

    Bhashkar Yadav

    727 posts

    Yes, you are correct. We can have query solution for it. Like:

    {exp:query limit="9" paginate="bottom" sql="SELECT exp_channel_titles.entry_id AS entryID FROM exp_channel_titles
       LEFT JOIN exp_channel_data ON exp_channel_titles.entry_id=exp_channel_data.entry_id
       WHERE exp_channel_titles.entry_id BETWEEN '[entry_id_from]' AND '[entry_id_to]'
       AND exp_channel_data.field_id_1='no' 
       AND exp_channel_data.field_id_2 >= 2500
       ORDER BY entry_date DESC"}
       
    {if no_results}
    
    [NO ENTRY]
    
    {/if}
    
     {exp:channel:entries channel="{channel_name}" entry_id="{entryID}"}
     
      [CHANNEL ENTRY CONTENT]
    
     {/exp:channel:entries}
    
     [HERE IS THE PAGINATION FROM THE SQL]
    
     {paginate}
      [PAGINATION URLS]
     {/paginate}
    
    {/exp:query}

    In above query you can see “field_id_1” and “field_id_2” should have custom field id in place of 1 and 2. You need to put [entry_id_from] and [entry_id_to] as par need.

    Please Note: I didn’t test above code.

    I hope, it would help you.


    Best Regards,

  • #5 / Dec 26, 2012 2:58am

    okaris

    4 posts

    Thanks Bashkar

    This will do it.

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

ExpressionEngine News!

#eecms, #events, #releases