0

I am hoping to use the channel entries tag to filter categories from 2 category groups- one category group is using the 'or' separator (|), and one cat group is using the 'and' separator (&). See my current attempt below.

{exp:channel:entries channel="some_channel" category="6|7|8|57 & 18" limit="15" paginate="top"}
  ...

This channel query should return entries of any of the categories '6,7,8,57', as long as they also have the category '18'. Is this possible? Or are there modules/extensions/etc. that would assist with this?

*Note- I need the results to be paginated, so I need to keep all the category-operations in the channel entries tag- ie. this would not work for me:

{exp:channel:entries channel="some_channel" category="6|7|8|57" limit="15" paginate="top"}
  {categories}
    {if category_id == 18}
      {!-- content --}
      ...

I am using EE2.8.1.

Thanks!

HERE IS MY ANSWER

I used PHP in the template to solve this (parse-stage on input).

$type_string = isset( $_GET['type'] ) ? $_GET['type'] : false;
$type = $type_string ? explode( ',', $type_string ) : false;
$service = isset( $_GET['services'] ) ? $_GET['services'] : false;

$entries = array(); 
// GET ALL CHANNEL ENTRIES IN CHANNEL
$channel_entries = ee()->db->select('entry_id')
    ->from('exp_channel_titles')
    ->where( array(
            'channel_id' => 8,
            'status' => 'open'
        )
    )
    ->get();
if ( $channel_entries->num_rows() > 0 ) :
    foreach( $channel_entries->result_array() as $channel_row ) :

        if( $type || $service ) :   
            // GET ALL ENTRY CATEGORIES
            $categories = ee()->db->select('cat_id')
                ->from('exp_category_posts')
                ->where( array(
                        'entry_id' => $channel_row['entry_id']
                    )
                )
                ->get();


            $cats = array();
            if ( $categories->num_rows() > 0 ) :
                foreach( $categories->result_array() as $category_row ) :
                    $cats[$category_row['cat_id']] = $category_row['cat_id'];       
                endforeach;
            endif;

            if( $type ) :
                if( count( array_intersect( $cats, $type ) ) > 0 ) :
                    if( $service ) :
                        if( isset( $cats[$service] ) ) :
                            $entries[] = $channel_row['entry_id'];
                        endif;  
                    else : 
                        $entries[] = $channel_row['entry_id'];
                    endif;
                endif;
            elseif( $service ) : 
                if( isset( $cats[$service] ) ) :
                    $entries[] = $channel_row['entry_id'];
                endif;
            endif;
        else :
            $entries[] = $channel_row['entry_id'];
        endif;  
    endforeach;
endif;

then in my channel entries tag i put:

{exp:channel:entries channel="portfolio" entry_id="<?= implode( '|', $entries ) ?>" orderby="<?= $orderby ?>" sort="<?= $sort[$orderby] ?>" limit="15" paginate="top"}
...
0
0

Low Search's Categories filter will allow you to do this, without PHP in your template. Simply use the Results tag as a replacement for the channel:entries tag, and you can use this:

{exp:low_search:results
    channel="some_channel"
    category:group1="6|7|8|57"
    category:group2="18"
    limit="15"
    paginate="top"
}

All parameters themselves are combined with AND, but each parameter itself can hold values that are queried with either AND or OR.

Using the Results tag like this doesn't require having or submitting a search form.

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