Craft CMS Asked by Dan Madoni on August 17, 2021
My client’s Craft 2 site includes several templates which use search functions to return a product entry by an ID, like so:
{% set product = craft.entries.section('Product')
.search('externalidentifier::' ~ craft.request.getParam('eid'))
.one() %}
This has been working without issue.
They just upgraded to Craft 3 however, and now these search functions don’t work. As a troubleshooting step, it works for me if I manually loop through all entries and grab the matching item as shown here:
{% set eid = craft.request.getParam('eid') %}
{% for prod in craft.entries.section('Product').all() %}
{% if prod.extenralidentifier == eid %}
{% set product = prod %}
{% endif %}
{% endfor %}
…but that only illustrates that the matching entries do exist and should be found with the search function. Any ideas why the search function would stop working after an upgrade to Craft 3?
The search
parameter relies on the internal search index (whereas your other approach does not).
It's possible that something got tripped up during a migration to Craft 3, perhaps when the new drafts & revisions system was introduced.
Try rebuilding your search index. It might take a long time to run, but should hopefully solve your problem.
Answered by Lindsey D on August 17, 2021
Lindsey D's answer above worked for me, the stumper for me was that the Rebuild Search Indexes feature that used to be in the Settings menu in Craft 2 is no longer there in Craft 3, (there is an Asset Indexes page in the Utilities menu, but that's not what we need here).
So to rebuild the search index in Craft 3, I needed to do this:
cd inetpubwwwrootmycraftsite
php craft resave/entries --update-search-index
References:
If there actually is a way to do this without resorting to console commands in Craft 3, please comment.
Answered by Dan Madoni on August 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP