I have two relationship fields. I am trying to query all entries where the first field is related to a particular element and the second field is related to nothing. Here is how I thought it would work but it doesn't.

$criteria->relatedTo = ['and',
    'targetElement' => anElementId,
    'field'         => 'relationshipOne'
    'targetElement' => null, // also tried ":empty:"
    'field'         => 'relationshipTwo'

1 Answer 1


Splitting the criteria up like this works.

$criteria->relatedTo = [
    'targetElement' => anElementId,
    'field'         => 'relationshipOne'
$criteria->relationshipTwo = ':empty:';

Thanks to @carlcs in the Craft Slack channel.

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.