Excluding post category in The Grid

Hi Support Team,

I am looking at a way to exclude pubished posts by category in a grid designed with The Grid.
I see how to select posts to display by category but there is no clear way to exclude them by category.

Is that even possible with The Grid plugin included with X?

Thanks a lor guys!

Hello There,

That option is not available by default. It is either, filter it with specific category or exclude specific post.
Their documentation is available here http://theme-one.com/docs/the-grid/

The usage of offset is similar to how you do it in WP_Query’s offset of WordPress, but this time, you’ll use it within The Grid’s code. Like from here

http://theme-one.com/docs/the-grid/#!/query_filter

The complete example is this, just by adding to child theme’s functions.php

function my_query_args($query_args, $grid_name) {
    if ($grid_name == 'grid name') {
        // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
        $query_args['cat'] = -11; /*11 is the category ID you want to exclude*/
    }
    return $query_args;
}
add_filter('tg_wp_query_args', 'my_query_args', 10, 2);

Hope this helps.

1 Like

Hi Lely,

This is very useful indeed, I’ll give it a try and let you know. However, I was hoping to find a more elegant way through meta key filtering directly in the configuration of a particular grid. What would be the right meta key name combination to use here in order to filter published posts with category not equal to a given slug?

Thank you so much for your support

David

Hey David,

Based on the Grid’s documentation, the meta key filter option is only for custom fields so you can’t use that to exclude categories.

Thanks.

Hi christian_y

I see, I understand. Well, I tried Lely’s recommendation and it worked like a charm.

Thank you guys!

Glad to hear it.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.