My question is this, I want to join a matrix table to a query and look for certain values in it. I am using this example below. I have 2 matrix fields partsModels.model and partsModels.parts. I need to make sure that all the criteria is met before looping through any of the data.

{% set entries = craft.entries.andWhere(['like', 'content.fields_myFieldHandle', 'foo']).all() %}

that Robin supplied here.

  • I cannot find any documentation on Craft's site on how to structure or code such a query. Has anyone done this before or used the andWhere on Matrix fields?
    – Vin
    May 16 '18 at 0:46
  • Seems like it be easier to just use search? It'll ultimately get translated to a like on the backend in most cases anyway. {% set entries = craft.matrixBlocks.search('*foo*').all() %}
    – Brad Bell
    May 17 '18 at 21:14
  • Thanks Brad. Since that searches through all instances of foo, it will capture things I don't want in the output. Plus I have two Matrix fields I need to compare before displaying the results. Like here craftcms.stackexchange.com/questions/26183/…
    – Vin
    May 17 '18 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.