ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

orderby= a custom field within a category

October 27, 2010 6:06am

Subscribe [4]
  • #1 / Oct 27, 2010 6:06am

    James Hurst

    48 posts

    Hey -

    I am trying to find a way of ordering a number of items; by a custom field within a category. My Category group id is 5 - but i’m not sure i’m referencing the custom field (lastname) correctly (well - I know i’m not doing it correctly; as it is definently not listing the items in ascending order based on that field)...

    Anyone got any tips about how to reference a custom field within a category?

    exp:weblog:entries weblog='shop_detail' relaxed_categories="yes" 
    category_group="5" orderby="lastname" sort="asc" limit="8"

    Thank you
    James

  • #2 / Oct 27, 2010 12:06pm

    James Hurst

    48 posts

    Sorry to bump up my own post…but I am losing hair at how hard i’m finding - trying to find an answer to this -

    anyone got any clues out there?

    Thank you!

    James

  • #3 / Oct 27, 2010 5:17pm

    Ingmar

    29245 posts

    What is “lastname”, a custom weblog field?

  • #4 / Oct 28, 2010 4:00am

    James Hurst

    48 posts

    Hi Ingmar; yup “lastname” is a custom field name within the custom field group number 5 (which is called “artists”) -

    What I would like to do is control a list of items; alphabetically (both from A - Z and Z - A) using this custom field for the sort order -

    I am bamboozled by it… and i’m sure the solution is going to be very simple!

    Thank you for your help -
    James

  • #5 / Oct 28, 2010 8:37pm

    Brandon Jones

    5500 posts

    Hi James,

    Can you confirm the version and build of EE 1.x you’re using? Does ordering by other fields work correctly?

  • #6 / Oct 29, 2010 5:06am

    James Hurst

    48 posts

    Hi Brandon; i’m using 1.6.9

    The template actually uses a whole bundle of sort orders - and i’ve noticed something very strange; my template (sorry its so long - but i’ve got a feeling that it might be that i’ve wrapped up all the sort orders within hte structure code which might trigger something?)

    I’ve just noticed (when you asked if the other sort orders are working) that actually each sort order gives a different set of results - so if I sort by date; I see a selection of entries sorted by date - but not all the entries; if I sort the entries ‘price high to low’ I see some of the entries - but not all the entries; and not the entries I see if I sort by date - its almost as if they have been divided into categories… am I referencing the wrong path name? I’ll have a little play and see if by removing the ‘category’ within the path helps - but if you notice anything else that could be tripping me up any help right now is much appreciated…

    All the best
    James

    <div class="span-24 last append-bottom">
                        <a href="http://{path=shop/category/date}">Date</a> | 
                        <a href="http://{path=shop/category/artist_a_z}">Artist A-Z</a> | 
                        <a href="http://{path=shop/category/artist_z_a}">Artist Z-A</a> | 
                        <a href="http://{path=shop/category/price_high}">Price ></a> | 
                        <a href="http://{path=shop/category/price_low}">Price < | </a>
                        <a href="http://{path=shop/category/lucky}">Lucky | </a>
                    {exp:weblog:categories weblog="shop_detail" style="linear" category_group="3" backspace="1"}
                        <a href="http://{path=shop}">{category_name}</a> |
                    {/exp:weblog:categories}
            </div>
    
                        {exp:structure:paginate parse="inward" show_first_last="no" mode="jumping"}
                {if segment_3 == "date"}
                    <h1>Date</h1>
        <div id="primary" class="wrap">
                        {exp:weblog:entries weblog='shop_detail' relaxed_categories="yes" orderby="date" limit="8"}
                {/if}
                {if segment_3 == "artist_a_z"}
                    <h1>By Artist A-Z</h1>
        <div id="primary" class="wrap">
                    {exp:weblog:entries category_group="5" orderby="lastname" limit="8"}
                {/if}
                {if segment_3 == "artist_z_a"}
                    <h1>By Artist Z-A</h1>
        <div id="primary" class="wrap">
                    {exp:weblog:entries category_group="5" orderby="lastname" limit="8" sort="asc" limit="8"}
                {/if}
                {if segment_3 == "price_high"}
                    <h1>By Price Low to High</h1>
        <div id="primary" class="wrap">
                        {exp:weblog:entries weblog='shop_detail' relaxed_categories="yes" orderby="price" sort="asc" limit="8"}
                {/if}
                {if segment_3 == "price_low"}
                    <h1>By Price High to Low</h1>
        <div id="primary" class="wrap">
                        {exp:weblog:entries weblog='shop_detail' relaxed_categories="yes" orderby="price" sort="desc" limit="8"}
                {/if}
                {if segment_3 == "lucky"}
                    <h1>Lucky Dip</h1>
        <div id="primary" class="wrap">
                        {exp:weblog:entries weblog='shop_detail' relaxed_categories="yes" orderby="random" sort="asc" limit="8"}
                {/if}
                {exp:weblog:category_heading weblog='shop_detail' relaxed_categories='yes'}
                    <h1>{exp:html_strip keep="h1"}{category_name}{/exp:html_strip}</h1>
        <div id="primary" class="wrap">
                {/exp:weblog:category_heading}
  • #7 / Oct 29, 2010 5:17pm

    Sue Crocker

    26054 posts

    Can we get structure out of the equation when testing?

  • #8 / Nov 02, 2010 5:13am

    James Hurst

    48 posts

    Hi Sue -

    Thanks - although taking structure out of the equation doesn’t seem to make any difference to the results.

    <h1>By Artist A-Z</h1>
        <div id="primary" class="wrap">
                    {exp:weblog:entries weblog="shop_detail" orderby="artistname" sort="asc" show_future_entries="yes" show_expired="yes" limit="8"}
                {/if}

    Currently the custom field “artistname” is a custom field within a category (called artists) - i’ve also tried creating a custom field outside of the categories within the shop_detail weblog - and that too doesn’t affect the sort order or results.

    With the price sorting

    {if segment_3 == "price_high"}
                    <h1>By Price Low to High</h1>
        <div id="primary" class="wrap">
                        {exp:weblog:entries weblog="shop_detail" orderby="price" sort="asc" limit="8"}
                {/if}

    If I remove the ‘limit’ I am faced with a white screen - in fact if I set the limit to around 53 for price asc or above - I am faced with a white screen - while if I set my limit to around 60 desc I am faced with a white screen (with and without structure pagination).

    For some reason sorting the price desc seems to pull the data in price order (with the most expensive first) - but pulling the data asc is a complete jumble…

    My two urgent questions are:

    Am I referring to a custom field within a category correctly (or do I need to wrap it in some sytax to make it clear that it is a custom field within a category) for the artist names.

    Do I need to define the custom field for the price as numbers / digits somehow or should a text field be fine?

  • #9 / Nov 02, 2010 4:48pm

    Ingmar

    29245 posts

    Am I referring to a custom field within a category correctly (or do I need to wrap it in some sytax to make it clear that it is a custom field within a category) for the artist names.

    I am not sure I follow. Is this not a regular channel custom field? You can use category custom fields in this tag.

  • #10 / Nov 03, 2010 8:36am

    James Hurst

    48 posts

    Hi Ingmar - it is a custom field within a category (so not a regular custom field) - do I need to do anything special to orderby=“a custom field within a category”?

    Many thanks -
    All the best
    james

  • #11 / Nov 03, 2010 5:02pm

    Ingmar

    29245 posts

    I am afraid you can’t orderby a category custom field within an exp:weblog:entries loop, at all. It will have to be a weblog custom field.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases