2

I'm trying to query up some entries based on a value inside an editable table.

Here's two pictures on how it's set up:
http://i.imgur.com/lJFcO1C.png
http://i.imgur.com/Eqxg7Uh.png

My current template (stripped) looks like this:

{% set courses = craft.entries({
    section: 'course',
    search: 'participants:31'
}) %}


<section class="user-dashboard">

    <h1 class="user-dashboard__upcoming-title">
        Upcomming courses
    </h1>

    {% for course in courses %}
        {{course.title}} <br>
    {% endfor %}

</section>

I've tried a couple of other parameters to the query, such as

participants['col4']: '31'

and

participants: '["col4"]:31'

but almost no dice. I get a result, but it matches with all the other values as well. I only want it to match with "userID" column, aka col4.

For example, I get the same results if I try '1' instead of '31'.

3

Craft saves all the table's data serialized to a single cell in the database, so there's not really a good way to set query conditions to match something in a table field.

What you could do is to use Andre Elvan's brand new plugin Preparse Field. With that you would add a new field to you entry type that does some predefined Twig logic on every entry save. So you could get that table cell's data you are interested in and write it to its own field that you could then use as a field parameter in your criteria model.

Another way, and this is the approach I would actually recommend, is to refactor the whole setup and use a separate channel to hold each table row as its own entry (without URL) and than have an Entries field to relate those to your week / event entry.

The third solution is a variant of the second one, but to use a Matrix field (or a SuperTable) instead of a separate channel. You would need to set up the query with Yi query builder from a custom little plugin. Let me know if you're interested in this solution and I can assist you in setting this up.

| improve this answer | |
  • Your second solution turned out to be the best in my case. Thanks for taking the time to answer. – Mosswalker Jun 15 at 20:43

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.