Skip to content

Add custom field to EntryQuery #15721

Closed Answered by brandonkelly
mikolamin asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the fields’ getValueSql() methods to get a SQL fragment that can be used in place of the column names:

// Get the “Event” entry type's field layout
$entryType = Craft::$app->entries->getEntryTypeByHandle('event');
$fieldLayout = $entryType->getFieldLayout();

// Get the fields we care about
$publishDateField = $fieldLayout->getFieldByHandle('publishDate');
$endDateField = $fieldLayout->getFieldByHandle('endDate');
$startDateField = $fieldLayout->getFieldByHandle('startDate');

$where = [
    'and',
    ['<=', $publishDateField->getValueSql(), $currentDate],
    [
        'or',
        [
            'and',
            [$endDateField->getValueSql() => null],
            ['>=', $s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mikolamin
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants