We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Group Grid entries by custom field

Development and Programming

nuvole's avatar
nuvole
14 posts
11 years ago
nuvole's avatar nuvole

I have a grid field like this:

File - Text field - Relationship field

Where the file is a document, the text field is the title and the relationship field is the argument.

I would like to output the list of files like this:

Argument 1 File 1 File 3 File 6

Argument 2 File 2 File 4 File 5

And so on, therefore grouped by the relationship field.

Now I have something like

{grid}

<li><a href="http://{grid:file}"> {grid:text_field} </a> - {grid:relationship}{grid:relationship:title}{/grid:relationship}</li>

{/grid}

That shows me:

File 1 - Argument 1 File 2 - Argument 2 File 3 - Argument 1 File 4 - Argument 2 File 5 - Argument 2 File 6 - Argument 1

How can I output the items by grouping them by argument? It means that the relationship field must shows only one time per type, and create a list for every type.

       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

I’m thinking you’ll need a custom query for this.

       
nuvole's avatar
nuvole
14 posts
11 years ago
nuvole's avatar nuvole

What do you mean?

       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

I mean a query which is custom..😉

When you create channel:entries tag pairs in templates what you are really doing is writing simplified SQL statements (queries) which EE uses to go to the database to fetch content.

Your use case isn’t within the current functionality of the relationship tag, so I’m suggesting you can use the Query module to write your own SQL statement to achieve the results you are looking for.

       
nuvole's avatar
nuvole
14 posts
11 years ago
nuvole's avatar nuvole

If I used Matrix and Playa instead of grid, I might be able to do it? I tried but did not succeed :-(

       
Boyink!'s avatar
Boyink!
5,011 posts
11 years ago
Boyink!'s avatar Boyink!

You’d be better off asking in the Pixel and Tonic support channels, but my gut feeling is no. You are after another level of grouping content.

But there may be a clever way to pull it off that I’m just not seeing.

       
nuvole's avatar
nuvole
14 posts
11 years ago
nuvole's avatar nuvole

I resolved using Matrix and Playa. I used those because of the Playa parents tag. I could not use the native features of Grid and Relationship because, according to the documentation, “Currently it is not possible to get the parents of a relationship field that is inside of a Grid field”.

The code is:

{exp:channel:entries channel="arguments"}
  {title}
  {exp:playa:parents channel="documents" var_prefix="doc"}
    {doc:matrix_field search:relationship="[{entry_id}]"}
      <li><a href="http://{file}">{text_field}</a></li>
    {/doc:matrix_field}
  {/exp:playa:parents}
{/exp:channel:entries}
       
muabancanho's avatar
muabancanho
6 posts
11 years ago
muabancanho's avatar muabancanho

Dear admin topic ! Who known add google + usefull seo ? | an gia garden

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.