I have recently started using the model service to query channel entries.

$query = ee('Model')->get('ChannelEntry')

I have been using EE's documentation to get by for most queries, but am now stuck.

I need to filter entries where a field matches a specific date. There is no mention of this in the documentation.

Previously, when I was able to query channel entries with a database call, I was using the following in a where clause:


Does anyone know of how this can be achieved using the model service?

  • Previously when you were using field_id_xx custom query, data was saved in same table (exp_channel_data). But in EE4, it saves in it's own table (exp_channel_data_field_xx) Commented Sep 26, 2018 at 14:50
  • You can still use filter for fields that are presented in channel_titles table.. i.e., entry_date Commented Sep 26, 2018 at 14:51
  • @Mufi Thanks for the comment. Are you suggesting I keep using a database call? In my query, I need to return multiple fields (which are now stored as tables, as you say), so isn't it best to use the model service?
    – ccdavies
    Commented Sep 26, 2018 at 14:57
  • No. Model works fine. Find my answer below Commented Sep 26, 2018 at 14:59

1 Answer 1

$data = ee('Model')->get('ChannelEntry')->filter('field_id_103', '>' , '1536677819');

This code works for me. Where field_id_103 is my field ID and 2nd parameter is operator (> , <, >=, <= etc.) and last parameter is db value that needs to check.

  • Thanks Mufi, but I need to be able to check that (in your example) 'field_id_103' is a specific day. Unless I am mistaken, your code is checking if the code is after the (day) timestamp.
    – ccdavies
    Commented Sep 26, 2018 at 15:03
  • So above code, field_id_103 is a date field that will store timestamp. 2nd parameter is on me, weather I want to check timestamp is greater then or less then. so if you have to check a day condition should be with 2 filter queries on same field. 1 will be starting timestamp of the day and 1 will be ending timestamp of the day. So you will get all entries for that day. Commented Sep 26, 2018 at 15:08
  • 1
    Thank you! I'm not sure why I didn't think of this!!
    – ccdavies
    Commented Sep 26, 2018 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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