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

Trying to select ONLY posts that DON’T have a category - Can someone write me a SQL script?

Development and Programming

navertise's avatar
navertise
5 posts
14 years ago
navertise's avatar navertise

I’ve spent all day (literally) trying every possible combination and order of channel entries, channel categories, category archives, and query module tags I could think of in an attempt to select JUST the posts from a specific channel that are uncategorized.

After hours of research and trial and error, I’ve come to the conclusion that I need a SQL script; however, while I’m pretty good at single-table stuff, I’m downright inept at multi-table SQL commands.

Could someone write me (or explain how to make) a quick SQL script to run in the Query module that selects posts from the database that are uncategorized? I know what needs to be done - select the posts from the exp_channel_data table that are in the chosen channel, then ignore those that have entry_id’s that coincide with those found in the exp_category_posts table. The problem is that I don’t know how to write a dual-table script.

Any help would be most appreciated - thnks!

[Mod Edit: Moved to the forum Community Help]

       
Dave @ Exp:resso's avatar
Dave @ Exp:resso
465 posts
14 years ago
Dave @ Exp:resso's avatar Dave @ Exp:resso

Try using:

{exp:channel:categories backspace="1" channel="your_channel"}
{category_id}|
{/exp:channel:categories}

This should give you a pipe separated list of ids. Then you should somehow be able to feed this into the channel:entries category=”” parameter. something like

{exp:channel:entries channel="your_channel" category="not {exp:channel:categories backspace="1" channel="your_channel"}{category_id}|{/exp:channel:categories}"}

That probably wont work due to parse order issues but there will be a way to make it work. You just need to get the list of cat id before the channel entries tag is parsed.

We’ve got a free string plugin that allows you to set/get strings from different places in the template. We haven’t released it yet but let me know if you want to try it. Our developers aren’t in at the moment (4am on a Sunday morning) so apologies I can’t help any more right now!

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

This should get you all the entry_ids of un-categorized entries in a particular channel:

SELECT entry_id FROM exp_channel_titles WHERE entry_id NOT IN (SELECT entry_id FROM exp_category_posts GROUP BY entry_id) AND channel_id = {channel_id}
       
navertise's avatar
navertise
5 posts
14 years ago
navertise's avatar navertise
This should get you all the entry_ids of un-categorized entries in a particular channel:
SELECT entry_id FROM exp_channel_titles WHERE entry_id NOT IN (SELECT entry_id FROM exp_category_posts GROUP BY entry_id) AND channel_id = {channel_id}

Thank you!!! This is exactly what I needed - works beautifully! Thank you so much!

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Your welcome.

       

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.