I suspect there's a simple query to be able to do this but it's not something I've tried before. I'm trying to create a user-friendly way for a client to, from within the category edit screen, to indicate that a given category should or should not display within a drop down on the site. The general idea is that while they may have 20 categories, only 3-5 of them would be seen as "primary" and therefore should display in the dropdown menu at the top of the site.

So for user friendliness, I though adding a custom category field with a simple select list of no vs. yes would be the way to go. But the channel categories loop doesn't have a search parameter, so I suspect that I will need a query to loop through the categories in the given group and pull out only those with the custom category field of "display" with a value of "yes".

Can a query expert out there help me out?

2 Answers 2


You can use this simple query with Query module:

{exp:query sql="SELECT exp_categories.cat_id, exp_categories.cat_name, exp_categories.cat_url_title FROM exp_categories 
LEFT JOIN exp_category_field_data ON exp_category_field_data.cat_id=exp_categories.cat_id 
WHERE exp_categories.group_id=2 AND exp_category_field_data.field_id_1='Yes'"}

<p>{cat_name} :: {cat_url_title} </p>


Please note the "field_id_1" within WHERE condition. You need to have id of field instead of '1' and field id can get from "Custom Category Fields" under "ID" column.

Hope, it would help you.


You could do it that way by setting a custom field if you wanted. I've done a similar thing recently and used GWcode Categories to simply call out that custom field:

{exp:gwcode_categories channel="my_channel" custom_fields="yes" cat_url_title="{segment_2}" style="linear" limit="5"}

You'll have complete control with GWcode categories to organise your categories as you choose and easy access to custom fields. You can also run conditional checks on them if they contain a yes/no value for displaying in the dropdown menu.

  • Handled that way though, it's going to return all categories and then within the loop I'd conditionally display the ones with "yes" - which I could do natively as well. I'd like to filter the categories before they're returned, ideally, much like the search param on the entries loop. I figure I should get better performance and variables like count, etc. would still be accurate. Apr 12, 2013 at 13:34
  • It depends on how fixed the categories are. You can limit by ID's, groups, etc. There's also entry_count for the counting purposes.
    – Ian Young
    Apr 12, 2013 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.