Show Entries based on content in a Matrix Field I have a product with a variant matrix field(productVariants). Inside each variant is the option to supply a sale price (salePrice).

On the front end, I'm trying to show a product grid of only products that are on sale. Sounds simple, but I can't for the life of me figure out the syntax.

Here's where I'm at so far using matrixBlock queries. A few things I am not clear on:


owner - what is the owner? Docs only say myEntry and I'm not on a page or in a loop to get the entry that the matrix field is a part of
fieldId - is this the matrix field ID or the ID of the text field with the value I'm searching for?
How do I target salePrice in the search syntax since it's one of the fields inside the Matrix field?



{% set myMatrixBlockQuery = craft.matrixBlocks.owner(myEntry).fieldId(33).type('text').search('salePrice:*') %}

{% set saleEntries = myMatrixBlockQuery.all() %}

{% for product in saleEntries %}
{{ product.title }}, etc...
{% endfor %}


I've spent a couple of hours in StackExchange and in the Craft docs and still can't wrap my head around the syntax for this situation so I appreciate your help!
I was finally able to piece this together using Brad's explanation of MatrixBlocks parameters and this thread Can I get an entry by Matrix Block ID?

Seems merge([block.owner.id]) was the piece I was missing to fold the MatrixBlock query back into an entries loop.

{# Find Matrix Blocks with field value #}
{% set blocks = craft.matrixBlocks.type('variant').fieldId(33).salePrice(':notempty:').all() %}

{# Get entry IDs #}
{% set saleEntryIds = [] %}
{% for block in blocks %}
    {% set saleEntryIds = saleEntryIds|merge([block.owner.id]) %}
{% endfor %}

{# Get entries with limit #}
{% set saleProducts = craft.entries.section('shop').id(saleEntryIds).limit(4) %}

{% for product in saleProducts.all() %}
    {{ product.title }}
    {% for block in product.productVariants.all() %}
        {{ block.salePrice }}
    {% endfor %}
{% endfor %}


Seems a little overly complicated - maybe there's an easier way to do it?