Answers.Body: <p>You're actually closer than you might think. All you need to do is add your field handles as parameters. I prefer to use the hash style of declaring parameters but either way will work, I just find this easier to read.</p>
  
  <pre><code>{% set params = {
    section : 'events',
    order : 'eventDate asc',
    eventDate : '&gt;=' ~ now,
    eventType : 'green',
    limit : '10'
  } %}
  
  {% for event in craft.entries(params) %}
  ...
  {% endfor %}
  </code></pre>
  
  <p>This method also allows you to easily modify the params hash for whatever reason. For example you might want to set the <code>eventType</code> value to be something else based on the value of a query parameter. To do that you could use the merge tag like so:</p>
  
  <pre><code>{% if craft.request.getParam('eventType') not empty %}
  
    {% set params = params | merge({
      eventType : craft.request.getParam('eventType')
    }) %}
  
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T04:59:37.160Z
Answers.Text: Shall you please show how to filter data with the condition "not equal to", suppose in above example i want to find row whose eventType is not equal to green, then how can I write, I have tried "-" for not but dont know why is not working, help me out
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:24:00.490Z
Answers.Text: @NeerajRathod Simply add 'not' like so: `{ eventType : 'not green' }`
Answers.UserDisplayName: Josh Angell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:37:43.067Z
Answers.Text: I found what is the actual issue, I have added fields in the section and section already have around 3000 entries. So when I am putting "not" its not giving desire result because fields which I have added right now that are not available in the entries which is already available in the section.
  Any solution for the same ?
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:39:48.713Z
Answers.Text: I have came up the solution is - to create a method under controller where i'll update all the entries with the newly added fields so in this way all the entries will have newly added fields. Shall i go for it, or you have any other suggestion
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:41:53.490Z
Answers.Text: @NeerajRathod That's exactly what I'd do - or you can just re-save the section and it will re-save all the entries automatically for you.
Answers.UserDisplayName: Josh Angell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:47:34.550Z
Answers.Text: If I re-save the section then will it affect entries which is already available in the section ?
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:50:16.057Z
Answers.Text: @NeerajRathod really? I thought it did.
Answers.UserDisplayName: Josh Angell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:52:25.170Z
Answers.Text: So better I go for the controller solution, correct ?
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T06:56:57.283Z
Answers.Text: @NeerajRathod sorry I misread your previous comment. It will re-save all your entries in that section. So just re-save the section. If that doesn't work then no harm done, just try the controller.
Answers.UserDisplayName: Josh Angell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T07:00:27.450Z
Answers.Text: ok, Thanks for you time and valuable suggestions :)
Answers.UserDisplayName: Neeraj Rathod
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-15T17:53:59.903Z
Answers.LastActivityDate: 2015-08-15T17:53:59.903Z
Answers.UserDisplayName: Josh Angell
Body: <p>I have a channel of events with a field ‘eventDate’ for the date/time of the event. Within that there are ‘types’ of events ‘eventType’. What would be the most efficient way of outputting the NEXT (future date from now) that is of the ‘eventType’ equal to ‘Green’?</p>
  
  <p>So far i’ve got </p>
  
  <pre><code>{% for event in craft.entries.section('events').order('eventDate asc') %}
  </code></pre>
  
  <p>Which will output the entries in the correct order based on the eventDate, but can i filter the query even further to include the conditionals to only output if the date is in the future like this conditional:</p>
  
  <pre><code>{% if event.eventDate|date("c") &gt; now|date('c') %}
  </code></pre>
  
  <p>And also include the conditional to only output if the eventType == ‘green’ like so:</p>
  
  <pre><code>{% if event.eventType == ‘green’ %}
  </code></pre>
  
  <p>So that i can set the ‘limit’ to whatever i want and ONLY have the entries that meet the conditionals be included before that limit is applied?</p>
  
  <p>I know that i can use the 'Search' like so:</p>
  
  <pre><code>{% for event in craft.entries.section('events').search('eventType:green').order('eventDate asc') %}
  </code></pre>
  
  <p>But A. Is that the most efficient and B. How do i also include only entries that are in the FUTURE from NOW based on the eventDate field?</p>
  
Tags: <entries><datetime><search><forloop><querystring>
Title: Advanced query/filter based on date and values
ThreadText: # Advanced query/filter based on date and values
  
  (Asked by: username_0 on 2015-08-15)
  
  I have a channel of events with a field ‘eventDate’ for the date/time of the event. Within that there are ‘types’ of events ‘eventType’. What would be the most efficient way of outputting the NEXT (future date from now) that is of the ‘eventType’ equal to ‘Green’?
  
  So far i’ve got
  
  ```
  {% for event in craft.entries.section('events').order('eventDate asc') %}
  
  ```
  
  Which will output the entries in the correct order based on the eventDate, but can i filter the query even further to include the conditionals to only output if the date is in the future like this conditional:
  
  ```
  {% if event.eventDate|date("c") > now|date('c') %}
  
  ```
  
  And also include the conditional to only output if the eventType == ‘green’ like so:
  
  ```
  {% if event.eventType == ‘green’ %}
  
  ```
  
  So that i can set the ‘limit’ to whatever i want and ONLY have the entries that meet the conditionals be included before that limit is applied?
  
  I know that i can use the 'Search' like so:
  
  ```
  {% for event in craft.entries.section('events').search('eventType:green').order('eventDate asc') %}
  
  ```
  
  But A. Is that the most efficient and B. How do i also include only entries that are in the FUTURE from NOW based on the eventDate field?
  
  **Tags:** entries, datetime, search, forloop, querystring
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-15. Score: 15 | Accepted answer
  
  You're actually closer than you might think. All you need to do is add your field handles as parameters. I prefer to use the hash style of declaring parameters but either way will work, I just find this easier to read.
  
  ```
  {% set params = {
    section : 'events',
    order : 'eventDate asc',
    eventDate : '>=' ~ now,
    eventType : 'green',
    limit : '10'
  } %}
  
  {% for event in craft.entries(params) %}
  ...
  {% endfor %}
  
  ```
  
  This method also allows you to easily modify the params hash for whatever reason. For example you might want to set the `eventType` value to be something else based on the value of a query parameter. To do that you could use the merge tag like so:
  
  ```
  {% if craft.request.getParam('eventType') not empty %}
  
    {% set params = params | merge({
      eventType : craft.request.getParam('eventType')
    }) %}
  
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_2**: Shall you please show how to filter data with the condition "not equal to", suppose in above example i want to find row whose eventType is not equal to green, then how can I write, I have tried "-" for not but dont know why is not working, help me out  
  > **username_1**: @username_2 Simply add 'not' like so: `{ eventType : 'not green' }`  
  > **username_2**: I found what is the actual issue, I have added fields in the section and section already have around 3000 entries. So when I am putting "not" its not giving desire result because fields which I have added right now that are not available in the entries which is already available in the section. Any solution for the same ?  
  > **username_2**: I have came up the solution is - to create a method under controller where i'll update all the entries with the newly added fields so in this way all the entries will have newly added fields. Shall i go for it, or you have any other suggestion  
  > **username_1**: @username_2 That's exactly what I'd do - or you can just re-save the section and it will re-save all the entries automatically for you.  
  > **username_2**: If I re-save the section then will it affect entries which is already available in the section ?  
  > **username_1**: @username_2 really? I thought it did.  
  > **username_2**: So better I go for the controller solution, correct ?  
  > **username_1**: @username_2 sorry I misread your previous comment. It will re-save all your entries in that section. So just re-save the section. If that doesn't work then no harm done, just try the controller.  
  > **username_2**: ok, Thanks for you time and valuable suggestions :)  
  
  ---
  
  