1

I am outputting a list of channel entries. Each entry has 2 category assignments but I need to sort the list alphabetically by one of the categories.

Here is my current code that sorts alphabetically by entry title:

{exp:channel:entries
                    channel="properties"
                    orderby="title"
                    sort="asc"
                    dynamic="no"
                    disable="category_fields|member_data|pagination"
                }
                <tr>
                    <td>{title}</td>
                    <td>{categories show_group="4"}{category_name}{/categories}</td>
                    <td>{categories show_group="5"}{category_name}{/categories}</td>
                    <td>{property_sqft}</td>
                    <td><a href="{url_title_path='our-properties/detail'}" class="pluslink">View Property</a></td>
                </tr>
                {/exp:channel:entries}

So I basically need to sort the entries by {category_name} of category group 5.

How can I achieve this?

Thanks for any help.

0

I would think this would be a good time to use Stash add-on. You could wrap your channel entries tags with Stash set_list, which would save the properties as a Stash variable, and then output the list and orderby/sort by the category 5 field. Overall you would end up with more options for ordering and sorting your list. See the Stash docs for set_list and get_list for info and examples. Basically it would look like:

{exp:stash:set_list name="my_list"}
    {exp:channel:entries
        channel="properties"
        orderby="title"
        sort="asc"
        dynamic="no"
        disable="category_fields|member_data|pagination"
    }
        {stash:item_title}{title}{/stash:item_title}
        {stash:item_cat_4}{categories show_group="4"}{category_name}{/categories}{/stash:item_cat_4}

        etc....

    {/exp:channel:entries}
{/exp:stash:set_list}


{exp:stash:get_list name="my_list" orderby="item_cat_5" sort="asc"}
    <tr>
        <td>{item_title}</td>
        <td>{item_cat_4}</td>

        etc...

{/exp:stash:get_list}
| improve this answer | |

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.