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.

Excluding Entries by Category + Exclude Entries based on custom field

May 23, 2012 9:16pm

Subscribe [4]
  • #1 / May 23, 2012 9:16pm

    Kubik101

    155 posts

    Howdy.
    Using EE’s native category= not is not ideal for me.

    I would like to declare one category and exclude entries from showing.

    Can this be done using query or something similar?

    I am also interested to know if the same thing can be done using a custom field, if custom field = black, exclude it.

    I am using AB Pagination for paging and showing item count, so don’t want this to be affected either.

    Cheers.
    =)

  • #2 / May 23, 2012 9:28pm

    ChiefAlchemist

    913 posts

    Howdy.
    Using EE’s native category= not is not ideal for me.

    I would like to declare one category and exclude entries from showing.

    Can this be done using query or something similar?
    =)

    Can you elaborate a bit as to why it’s not ideal and what it is you’re trying to do? Perhaps and example or two?

    With Query pretty much anything is possible. That said, it can get tricky at times and can sometimes be avoided.

  • #3 / May 23, 2012 9:37pm

    Kubik101

    155 posts

    Image gallery:

    {exp:channel:entries channel="channel-name" dynamic="no" orderby="photo_month" sort="desc" limit="48" paginate="custom" year="{segment_3}" category="not 79"}

    Above is the tag for the year archive.
    Images are put into many different categories and often assigned to more than one.

    For category=not to work I need to declare all the categories an image appears in for it to be excluded, which falls apart as one image may belong to 1,3,10 and another to 27,30,50.

    I am after a way where one category (or more) can be declared and for all entries that have been assigned to that/those category(s) although assigned to others are still excluded.

    I hope that clarifies things, it’s a little hard to explain.

  • #4 / May 23, 2012 10:22pm

    ChiefAlchemist

    913 posts

    I think I get it.

    You want to do this A, this B and this C and not that Y or that Z?

    Best I know, no can do. EE can do AND and it can do OR but you can not combine the two.

    You’ll either have to use QUERY or use an If to filter your results.

    Or perhaps I don’t understand? it’s been a long day. It’s probably me.

  • #5 / May 23, 2012 10:30pm

    Kubik101

    155 posts

    It’s really simple.

    I want to declare one category (perhaps more) and have no entries appear if they assigned to the categories declared.

    EE falls down, trust me, I think it even breaks after declaring more than 2 not’s.

    Do you have an example of how to exclude entries based on category(s)?

    And I am also interested in seeing this combined with declaring a value of a custom field and have entries excluded based on that too.

    I have never used query so need to be introduced.

    Cheers.
    +)

  • #6 / May 23, 2012 10:33pm

    Man With A Peg

    124 posts

    Scratch that, I see what you were are saying. Give me a few moments to write a query.

  • #7 / May 23, 2012 10:37pm

    Kubik101

    155 posts

    Thanks Chris.

  • #8 / May 23, 2012 10:50pm

    Man With A Peg

    124 posts

    The query is an eye full, but give something along these lines a try:

    SELECT DISTINCT ct.*, cd.*
    FROM exp_channel_titles ct
    LEFT JOIN exp_channels c ON (c.channel_id = ct.channel_id)
    LEFT JOIN exp_channel_data cd ON (cd.entry_id = ct.entry_id)
    LEFT JOIN exp_category_posts cp ON (cp.entry_id = ct.entry_id AND cp.cat_id IN (79,80,81))
    WHERE c.channel_name = "channel-name" AND cp.cat_id IS NULL AND YEAR(ct.entry_date) = {segment_3}
    ORDER BY cd.field_id_##
    ASC LIMIT 48

    As usual with SQL queries, you should definitely escape {segment_3}. Also note that you need to know the field ID # that you are sorting by. There is no easy way around that with the design of the EE database.

  • #9 / May 23, 2012 10:57pm

    Kubik101

    155 posts

    Thanks.
    I have never tried using query before.
    Where do I add it in my code?

    {exp:channel:entries}
    {image}
    {paginate}
    {pagination_links}
    {/paginate}
    {/exp:channel:entries}
  • #10 / May 23, 2012 11:08pm

    Man With A Peg

    124 posts

    Basically, when you use a query, the fields from the database are given tags. So:

    {exp:query sql="[from above]"}
    {title}
    {entry_id}
    {field_id_1}
    {field_id_2}
    &c.
    {/exp:query}

    If you need the {exp:channel:entries} syntax, you may try passing in the {entry_id} value from the database, like so:

    {exp:channel:entries entry_id="{entry_id}" dynamic="no"}{/exp:channel:entries}
  • #11 / May 24, 2012 8:42am

    ChiefAlchemist

    913 posts

    If you use Low’s Seg2Cat you can avoid using the segment name in the query. (Which I only read quick so perhaps you should ignore this comment).

    Seg2Cat is beautifully simple. It takes a segment and gives you the cat # of it. It takes using categories to control content to a new level.

    p.s. Also, so this thread is saying that you can’t have a NOT that applies to more than one category? The limit on NOTs is just one cat? Really? Wow…learn something new everyday, eh?

  • #12 / May 24, 2012 9:03am

    Man With A Peg

    124 posts

    I am pretty sure you can use multiple values with NOT. The problem was that the OP has categories:

    cat1
    cat2
    cat3

    He has image1 in cat1/cat3 and image2 in cat2/cat3. He wants to show the images that are not in cat2, but because image1 and image2 are in cat3, they both get shown.

    Or that is how I am reading his question. 😉

  • #13 / May 24, 2012 9:35am

    ChiefAlchemist

    913 posts

    Epic

    Yeah, I think you got it right. I ran into similar a couple months ago and ended up writing some SQL statements.

    As I told a colleague, “Basic EE Cats can do AND and they can do OR but they can’t really do both.”

    This is a both 😊

  • #14 / May 24, 2012 9:33pm

    PhilBrienesse

    187 posts

    Any particular reason why it has to be categories for the exclude from showing portion? Why not use a custom status? May not work for the situation but just a thought.

    Or with the custom field that could certainly be done.

    {exp:channel:entries remainder_here}
      {if custom_field != "exclude"}
        display code here
      {/if}
    {/exp:channel:entries}
  • #15 / May 24, 2012 11:03pm

    Kubik101

    155 posts

    @PhilBrienesse
    Doing if statements will stop the entries from showing but will still attribute to your paging and any item counts, thus giving me blank pages in my case as this is a huge image gallery I am working on.
    =)

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

ExpressionEngine News!

#eecms, #events, #releases