XF 2.1 Examples of working with custom thread fields in thread finder?

Kevin

Well-known member
I've worked with using thread finder before but not with trying to include custom thread fields in my criteria. Below is exactly what I'm after.

I'll be having two custom thread fields, a start date and an end date. Neither field will be required and because I can't easily specify that end date is required when a start date is entered (and vice versa) either field may or may not have a value.

So what I'm after would be this:

Get a list of threads where...​
  • (Either Start Date has a value or End Date has a value) and;
    • ((Start Date has a value and is today);
    • or (Start Date has a no value and End Date has a value that is greater than or equal to today);
    • or (Start Date has a value less than or equal to today and End Date has a value greater than or equal to today));
Any insight appreciated. I don't need details about using finder in general or other basics, just how to incorporate using the custom forum fields into my criteria.

Thanks :)
 
The thread entity/table only contains a cache of the custom field values, so they can't really be queried directly. You'd have to query the pivot table (xf_thread_field_value) to get the corresponding thread_ids and then query for the threads separately.
 
.example: $this->finder('XF:Thread') ->where('CustomFields|my_field_id.field_value', '=', 'search')
Replace my_field_id with any field ids
 
Oops, I had checked for relations on the ThreadFieldValue entity but not the other way around.
 
Thanks, @021, I'll give that a try. :cool: If I get it working the way I'm thinking I've got a few different widgets in mind that use it.

Thanks, @Jeremy P, knowing the xf_thread_field_value table is out there might come in handy for some other things as I dig into different ideas.
 
Back
Top Bottom