Skip to main content
edited body
Source Link
Rosana Ruiz
  • 533
  • 4
  • 15

How do you query an Element by a custom field in Craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws an exception. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craftCraft 2 and neither they work.

How do you query an Element by a custom field in Craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws an exception. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craft 2 and neither they work.

How do you query an Element by a custom field in Craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws an exception. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for Craft 2 and neither they work.

It has actually nothing to do with a custom field type
Source Link
Robin Schambach
  • 19.8k
  • 1
  • 20
  • 45

How do you query an Element by a custom field in craftCraft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws an exception. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craft 2 and neither they work.

How do you query an Element by a custom field in craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craft 2 and neither they work.

How do you query an Element by a custom field in Craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws an exception. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craft 2 and neither they work.

Source Link
Rosana Ruiz
  • 533
  • 4
  • 15

How to query an entry by a custom field in Craft 3

How do you query an Element by a custom field in craft 3? My first try, according to craftcms/docs was:

$country = Entry::find()
                ->section('countries')
                ->where(['LIKE', 'code', 'CA'])->one()

But this throws. Here code is a custom text field. I've also tried some answers on stack exchange and many other combinations but they're for craft 2 and neither they work.