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.

Order by date using custom field

September 14, 2012 3:59pm

Subscribe [2]
  • #1 / Sep 14, 2012 3:59pm

    soopafly

    5 posts

    This question may be related to a resolved thread.

    Hi guys,
    I’m trying to work out a bug with a client’s News page.  This is an overview page that basically displays all news items, which a user can then click in to “read more”  I’m having a difficult time trying to sort these entries by “newest first”.  The field is set up using Matrix with one column using the EE native date entry field.  This is the field I would like to sort by.  But when viewing the page, the News entries are sorting by the entry date, and not the date in the custom field.  Here is my template code.  It’s set up so that if no custom date is entered, it will use the entry date.  The custom field name is “newsdate”.  Also running EE version 2.4 Any help would be great!!

    {exp:channel:entries channel="news" status="open|hidden" disable="categories|category_fields|member_data|pagination|trackbacks" start_on="2012-01-01 00:00" stop_before="2012-12-31 00:00" dynamic="no" show_future_entries="no" orderby="newsdate" sort="desc"}
            {if status == 'open' || member_group == '1'}  {!-- superadmins see hidden entries --}
              {news_article}
                <li>
                  {exp:ce_img:pair src="{logo}" width="100"}{made}{/exp:ce_img:pair}
                  
                    <a href="http://{page_url}" title="{title}">{title}</a><span>{if newsdate == ""}{entry_date format="%m.%d.%y"}{if:else}{newsdate format="%m.%d.%y"}{/if} | <em>{source}</em></span>
                    {blurb}
                  
                </li>
              {/news_article}
            {/if}
          {/exp:channel:entries}
  • #2 / Sep 17, 2012 3:45pm

    Dan Decker

    7338 posts

    Hi soopafly,

    I’m afraid you can’t order by a date field in a Matrix column. Channel Entries has no knowledge of that column until inside the tag pair, and then inside the matrix pair.

    Part of the issue is that Matrix stores its data in a separate table, and in a serialized array.

    Now, if that date field were in the channel fields proper, it should work.

    You may want to check out Low Reorder. It let’s you built result sets based on custom ordering.

    Cheers,

  • #3 / Sep 17, 2012 9:00pm

    soopafly

    5 posts

    Thanks Dan,
    So if I take that Date field out of the Matrix column, it would be possible to order by that custom date?

  • #4 / Sep 20, 2012 4:42pm

    Shane Eckert

    7174 posts

    Hey there soopafly,

    It should be possible once that field is no longer a Matrix FT.

    Is there anything else I can help with?

    Cheers,

  • #5 / Sep 20, 2012 5:06pm

    soopafly

    5 posts

    Thanks Shane.. I’ll try that!

  • #6 / Sep 21, 2012 5:11pm

    Shane Eckert

    7174 posts

    Hey soopafly,

    Please let us know how it goes!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases