Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix Block Query Doesn't Return Results When Field ID and Search are Used #9679

Closed
cakleimeier opened this issue Aug 4, 2021 · 4 comments
Labels

Comments

@cakleimeier
Copy link

Description

I have a site with a Matrix Block field whose ID is 262. Each Type in this field has a subfield with the handle menuText. I'm looking for all Matrix Blocks in that field belonging to the current entry whose menuText field is not empty.

I can return results if either the fieldId parameter or a search parameter is used in the matrixBlocks query. However, I cannot return results if both parameters are used. Additionally, using any kind of search seems to return all the blocks, rather than actually applying that search.

For reference, here's my query. The variable page is defined in the loop in which this query exists.
{% set matchingBlocks = craft.matrixBlocks.owner(page).fieldId(262).menuText('*').all() %}

Also note that, for the search parameter, I've tried many variations with either all results or no results. Some variations I've tried include:

.menuText(':notempty:')
.search('menuText:*')
.search('menuText:notempty:')
.search({query : 'menuText:*'})

Finally, I've ensured that the setting "Use this field’s values as search keywords" is on for the Matrix field itself and for the menuText subfield.

My main concern here is that fieldId and search don't seem to work together, as I need to specify fieldId in order to access the custom field content of the results, according to the docs. Without being able to combine these parameters, I won't be able to search for the matching blocks and return the contents of those matches with the same query.

Steps to reproduce

  1. Create a matrix field with several block types, each containing a subfield of the same name
  2. In the template, write a matrixBlocks query to search for matches in the subfield, using fieldId

Additional info

  • Craft version: 3.7.7
  • PHP version: 7.3.7
@brandonkelly
Copy link
Member

brandonkelly commented Aug 5, 2021

Thanks for reporting that! Not really sure how we’ve made it this far without anyone noticing, but apparently we never added support for fieldHandle:keyword search syntax for Matrix block queries.

I’ve just fixed that for the next release. To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 3.7.7" and run composer update.

@cakleimeier
Copy link
Author

Thanks for the reply; I'm glad to know I wasn't missing something. :)

@brandonkelly
Copy link
Member

Craft 3.7.8 is out now with the fix for this.

@cakleimeier
Copy link
Author

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants