We have a date field with search indexing enabled in certain entry types, but the keywords column in Craft's search index stays empty and the date is therefore not searchable.
Please note we are using a multisite setup and the keyword column is empty for each multi site row in the searchindex table.
You鈥檒l probably have better luck working directly with the Date/Time field鈥檚 query param rather than going through search, which isn鈥檛 really intended for numerical/date values.
Does this work in the CP as well? We are trying to find entries matching a certain date in a certain field.
Good question. There鈥檚 currently no built-in way to set a Date/Time field鈥檚 query param from the control panel, but we鈥檙e working to make that possible in Craft 4.
In the meantime, if you are running Craft 3.4.4.1 or later, you could add a date range picker to element indexes yourself, using the CP JS plugin and some custom JS code:
// Is this the Entries index page?
if (Craft.elementIndex && Craft.elementIndex.elementType === 'craft\\elements\\Entry') {
// Add a date range picker to the toolbar
let startDate = endDate = null;
Craft.ui.createDateRangePicker({
onChange: function(s, e) {
startDate = s;
endDate = e;
Craft.elementIndex.updateElements();
},
}).appendTo(Craft.elementIndex.$toolbar);
// When the element index is updated, set our Date/Time field param
Craft.elementIndex.on('registerViewParams', function(event) {
event.params.criteria.myDateTimeField = ['and'];
if (startDate) {
event.params.criteria.myDateTimeField.push('>=' + (startDate.getTime() / 1000));
}
if (endDate) {
event.params.criteria.myDateTimeField.push('<' + (endDate.getTime() / 1000 + 86400));
}
});
}
(Replace myDateTimeField with your actual Date/Time field handle.
Works perfectly! Thanks!
Most helpful comment
Good question. There鈥檚 currently no built-in way to set a Date/Time field鈥檚 query param from the control panel, but we鈥檙e working to make that possible in Craft 4.
In the meantime, if you are running Craft 3.4.4.1 or later, you could add a date range picker to element indexes yourself, using the CP JS plugin and some custom JS code:
(Replace
myDateTimeFieldwith your actual Date/Time field handle.