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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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