I wish to have a custom fieldtype which contains the standard datetime field abilities along with storing an extra piece of data. I have created a custom fieldtype for this with a mixed attributetype to store the data as JSON.

However I am having problems when I try to query some of the data from the frontend.

For example to pull out a specific piece of data I am currently doing:


This correctly pulls out the date I have stored. However when using this in the example:

craft.entries({ type: 'sectionName', customFieldtype.date: '>=' ~ now|date(c) }).order('customFieldtype.date asc').first()

I get errors as when Craft converts this to SQL it's converting these to column names and customFieldtype.date doesn't exist.

Is there any way around this bar having to re-create the built in craft entries calls in pure SQL?


Just in case anyone else comes across this problem in the future I actually managed to figure it out myself.

I created kept the fieldtype as a DateTime field and grabbed the date/time and the extra value within the prepValueFromPost function then pushed the extra data into a custom table and post just the datetime to the craft_contents table.

Then within the getInputHtml function I grabbed the extra data from the custom table to display along with the date/time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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