2

Is it possible to filter relations entries field by a category in a control panel entry?

I would like to relate two channels using the entries field but I have 100 source entries so I was hoping to be able to filter the list by category to narrow down what is shown in the target entry. Similar to how EE Playa works which allows me to choose the category in which to pull the related entries from when I initially set up the custom field.

Here's a similar thread: Filtering/searching for entries by category in the control panel

1

No, this is currently not possible, but there's a feature request on Craft's feedback site that you could vote for: "Entry Type" setting for Entries fields.

As Lewis Jenkins mentioned there, you could use his plugin Dynamic Fields as a workaround solution in the meantime. Something like this should give you a dropdown field with all "myOtherChannel" entries related to a category "myCategory".

{% set category = craft.categories.group('myCategoryGroup').slug('myCategory') %}
{% set entries = craft.entries.section('myOtherChannel').relatedTo(category).order('title asc') %}

{% for entry in entries %}
    { "value": "{{ entry.id }}", "label": "{{ entry.title|raw }}" }
    {% if not loop.last %}, {% endif %}
{% endfor %}
  • I'm actually wanting to do this solely in the control panel entry not on a template output page. I basically want to be able to relate two channels and rather than pulling all 100 entries that exist in the source channel, I would like to be able to set up the relations field in the admin to filter according to a category. That way when I create a new entry in the target channel, instead of pulling up 100 entries to choose from, I will pull up say 10 that have the category I selected when setting up the field. – Lori Mar 30 '15 at 18:56
  • My workaround may be to create multiple category groups instead of having one category group. – Lori Mar 30 '15 at 19:07
  • Lori that code is meant to go into the Dynamic Fields settings. It's not template code for the front end, but responsible for which entries are going to be available in the dropdown field in the Edit Entries view in your CP. – carlcs Mar 30 '15 at 23:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.