Return entries where custom field partially contains My entries have a field containing a third-party product id and a price, separated by a hyphen, like so:

p666a-12.99


In the template, a plugin is returning me some product ids, and I want to return all entries containing those product ids. I know I can fetch all entries, reduce the custom field down to the product id and compare it to the product ids returned from the plugin, but that seems a bit tardy.

Can I filter my entries using the custom field directly?

{# pluginIds = 'p666a, p678a' #}
{% set entries = craft.entries.section('sectionName').customField(pluginIds) %}
You could use the Preparse plugin to save the product ID part of your field in a new hidden field.

Add a new "productId" Preparse field to your entry type with this code in the field's settings:

{{ entry.customField|split('-')|first }}


To update all existing entries, re-save them by going into Settings → Sections → Section Name and click Save.
You can now set up a criteria model exactly like you mentioned in your question, except that you now use the
Preparse field as your custom field parameter:

{% set entries = craft.entries.section('sectionName').productId(pluginIds) %}