Hi all. I am NOT a mysql pro, but need a custom mysql queries some I’m here for help. I’ve turned on the sql queries so I can see what is being called by tags that do nearly what I want. Here’s the EE code I’m using:
{exp:weblog:categories style="linear" category_group="5" weblog="classifieds" show_empty="no"}
<li><a href="#{category_name}">{category_name}</a></li>
{/exp:weblog:categories}That I believe results in:
{exp:query sql="SELECT DISTINCT(exp_categories.cat_id), parent_id FROM exp_categories LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id LEFT JOIN exp_weblog_titles ON exp_category_posts.entry_id = exp_weblog_titles.entry_id WHERE group_id IN ('5') AND exp_weblog_titles.site_id IN ('1') AND exp_category_posts.cat_id IS NOT NULL AND exp_weblog_titles.status != 'closed' ORDER BY group_id, parent_id, cat_order"}
{category_id}
{/exp:query}So a couple of things. This latter just spits out {category_id} instead of any content. But more importantly, I want to add another condition…
in layman’s terms: I want all category names from category 5 associated with the “classifieds” weblog that are not empty. I then want to narrow this list using only entries from “classifieds” that are in a particular “edition” via a relationship. Here’s my structure:
classifieds weblog: - category group 5 - relationship field to edition weblog (jan/feb/march)
classifieds page should be able to be edition limited… we don’t want to show a classified entry from last November, but only the current ones…
any help would be greatly appreciated!!!
This query should at least get you the category names you want from group 5 that are assigned to entries, I’m not sure what you mean about the relationships.
SELECT DISTINCT exp_categories.cat_id , exp_categories.cat_name
FROM exp_categories
JOIN exp_category_posts ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE exp_categories.group_id = 5And change {category_id} to {cat_id} and you should see values popping up. Those tags should correspond to the ones in your SELECT statement, so to print the category name, put {cat_name}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.