People who code: we want your input. Take the Survey

New answers tagged


I've also run into this problem. I've checked the API documentation both for craft\elements\Entry and craft\base\Element and neither seem to have a simple, straightforward method to check if a field exists. Here are a couple of options I have found: Getting the list of fields You can get the list of fields by going through the field layout: // this works ...


Without modifying your code too much, you could simply add an exception handler with a try/catch block. Another method would be to retrieve the field handles for the entry type's field layout, and check for a match: Getting the $entryType as necessary, $etFieldHandles = []; $fields = $entryType->getFieldLayout()->getFields(); foreach ($fields as $field)...

Top 50 recent answers are included