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.

Displaying Custom Field Entries AND Sorting

June 21, 2010 11:03am

Subscribe [3]
  • #1 / Jun 21, 2010 11:03am

    igrandfunk

    13 posts

    I am wanting to sort by country and product. The countries need to be listed in one pull down menu and the products listed in another pull down menu. When the user chooses a particular country or product from these menus (custom fields by the way), the entries need to be sorted accordingly. Any help is greatly appreciated, thanks!

    http://www.mobywrap.eu/index.php/store-locator

  • #2 / Jun 21, 2010 11:19am

    Neil Evans

    1403 posts

    Look in the docs!
    http://expressionengine.com/docs/modules/weblog/parameters.html#par_orderby

    Order by multiple elements separated by pipes.

  • #3 / Jun 21, 2010 11:22am

    Neil Evans

    1403 posts

    you also probably want this doc file as well:
    http://expressionengine.com/docs/modules/weblog/dynamic_parameters.html

    but please use the docs!

  • #4 / Jun 21, 2010 2:46pm

    igrandfunk

    13 posts

    Hey! Thanks for your reply. I am currently using the code mentioned in the docs above:

    <form action="{path='database/index'}" method="post">
        <select name="orderby">
            <option value="title">Company Name</option>
            <option value="country">Country</option>
            <option value="products_offered">Product</option>
        </select>
    <select name="sort">
    <option value="asc">Ascending</option>
    <option value="desc">Descending</option>
    </select>
        <select name="limit" id="limit">
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option selected value="100">100</option>
            <option value="1000">All Entries</option>
        </select>
    <input type="submit" value="Submit">
    </form> 
    
    
    
    
    <table cellspacing="0" class="list">
      <tr>
        <th>Company Name</th>
        <th>Address 1</th>
        <th>Address 2</th>
        <th>City</th>
        <th>State/Province
    /Region</th>
        <th>Zip/Capital</th>
        <th>Country</th>
        <th>Telephone</th>
        <th>Web</th>
        <th>Store Type</th>
        <th>Products Offered</th>
      </tr>
    
    
    
    
    {exp:weblog:entries weblog="eustores" sort="asc" orderby="title" dynamic_parameters="orderby|limit|sort"}
      
    
    <tr class="{switch="odd|even"}">
        <td>{title}</td>
        <td>{address1}</td>
        <td>{address2}</td>
        <td>{city}</td>
        <td>{state_province_region}</td>
        <td>{zip_capital}</td>
        <td>{country}</td>
        <td>{telephone}</td>
        <td><a href="http://{url_address}" target="_blank" rel="noopener">{url_address}</a></td>
        <td>{storetype}</td>
        <td>{products_offered}</td>
      </tr>
    {/exp:weblog:entries}
    </table>

    However, my question is how do I display the values from the custom field country in a drop down menu? And if a user chooses a value, how can it sort the entries based on that value in the custom field?

    Does that make sense?

    Thanks!

  • #5 / Jun 21, 2010 4:06pm

    igrandfunk

    13 posts

    Well I have finally found some clarity. Apparently, MSM has issues with the search parameter (not noted in the documentation BTW):

    http://ellislab.com/forums/viewthread/80807/
    http://ellislab.com/forums/viewthread/130758/
    http://ellislab.com/forums/viewthread/68133/P0/

    Gonna have to find another work around.

    - A

  • #6 / Jun 22, 2010 11:58am

    igrandfunk

    13 posts

    The latest. Got the search with dynamic parameters to work. But now I need a solution for MSM. Any ideas?

  • #7 / Jun 22, 2010 12:01pm

    Neil Evans

    1403 posts

    i assume you are following the docs and using the site prefix before the custom field?

    Multiple Site Manager and orderby=

    The orderby= parameter can accept a site short-name in the namespace.
    orderby=“default_site:body|second_site:summary”

    When ordering by multiple custom fields from multiple Sites, one must remember that entries from another site will have no data for that field, and the entries will be ordered as such. This results in ordering entries by Site and then Custom Field(s):
    orderby=“default_site:body|second_site:summary”

    Will result in:
    Default Site - Entry One - Albert
    Default Site - Entry Two - Bobby
    Second Site - Entry One - Alligator
    Second Site - Entry Two - Buffalo

    If you have multiple Sites where each site has a custom field with the same, exact short name, then you can specify that short name (without the site specified) and ExpressionEngine will treat those two fields as the same value and be able to order them as if they were the same field:

  • #8 / Jun 22, 2010 12:09pm

    Miguel Garcia

    2 posts

    Hey nevsie! Thanks for your help. I am using the search pipe not orderby. Below is my code:

    <select name="search:products_offered">
    <option value="">Product</option>
    <option value="Patapum">Patapum</option>
    <option value="Moby">Moby</option>
    <option value="Hotslings">Hotslings</option>
    <option value="Ellaroo">Ellaroo</option>
    <option value="Patapum Nappies">Patapum Nappies</option>
        </select>
    <select name="sort">
    <option value="asc">Ascending</option>
    <option value="desc">Descending</option>
    </select>
        <select name="limit" id="limit">
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option selected value="100">100</option>
            <option value="1000">All Entries</option>
        </select>
    <input type="submit" value="Submit">
    </form> 
    
    
    
    
    <table cellspacing="0" class="list">
      <tr>
        <th>Company Name</th>
        <th>Address 1</th>
        <th>Address 2</th>
        <th>City</th>
        <th>State/Province
    /Region</th>
        <th>Zip/Capital</th>
        <th>Country</th>
        <th>Telephone</th>
        <th>Web</th>
        <th>Store Type</th>
        <th>Products Offered</th>
      </tr>
    
    
    
    
    {exp:weblog:entries weblog="eustores" sort="asc" orderby="title" dynamic_parameters="limit|sort|search:country|search:products_offered" search:country="" search:products_offered=""}

    I’ll try orderby now. Thank you for your assistance. Any more advice is welcomed!

  • #9 / Jun 22, 2010 12:47pm

    igrandfunk

    13 posts

    I think I originally used the search parameter because I want to sort by a value in the custom field. I don’t want to sort by the custom field (orderby).

    <select name="search:products_offered">
    <option value="">Product</option>
    <option value="Patapum">Patapum</option>
    <option value="Moby">Moby</option>
    <option value="Hotslings">Hotslings</option>
    <option value="Ellaroo">Ellaroo</option>
    <option value="Patapum Nappies">Patapum Nappies</option>
    </select>

    Can this be done via orderby?

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

ExpressionEngine News!

#eecms, #events, #releases