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

List all available options from a channel field?

How Do I?

Peak Creative's avatar
Peak Creative
6 posts
6 years ago
Peak Creative's avatar Peak Creative

Noob here. I’ve scoured the documentation for EE 2.x (unfortunately we’re stuck working in this version).

I’m NOT wanting to output the channel field values selected for a specific entry which looks simple enough–I’m wanting to just list ALL the values/IDs from a custom channel field so I can populate select box options on the frontend with ALL the options available.

Probably simple, but I can’t find the template tag/syntax for how to do this. Thank you!

       
WinkingFrog's avatar
WinkingFrog
89 posts
6 years ago
WinkingFrog's avatar WinkingFrog

Hey,

If I understand your needs correctly, all you need is a basic channel entries tag, without imposing limits?

So for example…

<select>
{exp:channel:entries channel="options" dynamic="no"}
    <option value="{value}">{value}</option>
{/exp:channel:entries}
</select>

…should give you what you want. You could also use sort and orderby parameters to fine tune the order in which the entries are used etc.

Is that what you meant?

       
Peak Creative's avatar
Peak Creative
6 posts
6 years ago
Peak Creative's avatar Peak Creative

I don’t think so. Let me give you context and maybe that will help you help me. 😊

I have a channel named Resources. I have set up a channel field group for that channel (Resource Fields). In Resource Fields are all sorts of data fields: address, phone, email, etc. One of those fields is a multiselect named Counties in which all the counties to choose from are listed. So when someone publishes a new Resource entry, they can select which counties they want to apply to that resource.

However, all I’m trying to do is create a fieldset in a form in a template that lists all of the counties that are set up in that channel field…NOT as they apply to any one channel entry but just ALL the options available in the channel field in the admin.

       
WinkingFrog's avatar
WinkingFrog
89 posts
6 years ago
WinkingFrog's avatar WinkingFrog

Ah, I get you…

As far as I can tell, the only way you can do that is by using a query tag, and allowing PHP in the template (Output Parse).

<select multiple>
{exp:query sql="SELECT field_list_items FROM exp_channel_fields WHERE field_name = 'countries' "}
 <?php $countries = explode("\n", "{field_list_items}");
 foreach ($countries as $country){
  echo "<option value='".$country."'>".$country."</option>";
 }?>
{/exp:query}
</select>

Obviously you will have to check your database prefix and field shortname, but something like that would work for you I think?

It’s a bit hacky, but gets the job done 😉

       
Peak Creative's avatar
Peak Creative
6 posts
6 years ago
Peak Creative's avatar Peak Creative

Thanks. This is at least got me up to speed on how to think about this in an EE kind of way.

       
Peak Creative's avatar
Peak Creative
6 posts
6 years ago
Peak Creative's avatar Peak Creative

I’m going to tack this on here, as it’s somewhat related.

The name of my channel field is resource_counties, and {resource_counties} outputs the list of whatever counties were selected from the multiselect channel field within the loop. Cool.

Is there a parameter to count how many items are in it? {resource_counties:count_results} or something simlar to that? Or does this also have to be done via PHP/SQL?

       
WinkingFrog's avatar
WinkingFrog
89 posts
6 years ago
WinkingFrog's avatar WinkingFrog

I suspect you would have to resort to PHP to make the count yourself, hopefully someone will correct me if I’m wrong. Whilst the entries tag itself has a {total_results}, to the best of my knowledge there is not a counter in place for use inside a field tag pair. Might be quite handy though!

       

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.