Exclude multiple categories in The Grid

Hi
I have edited my functions.php to exclude a category from The Grid but would like to be able to do it with multiple categories. Here in the function:

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

I added a comma between the categories, is this not right?

Thanks

Hi There,

Could you please try with this code?

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

For more information, please take a look here: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters.

Let us know how it goes!

Sorry, maybe I was not clear. I want to be able to exclude categories from several different GRIDS. In the original I put a comma inbetween the grid names as bolded below:
function my_query_args($query_args, $grid_name) {
if ($grid_name == ‘New Releases Concord Page,New Release RECORDS Page Grid’) {
// all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
$query_args[‘cat’] = -2037; /11 is the category ID you want to exclude/
}
return $query_args;
}
add_filter(‘tg_wp_query_args’, ‘my_query_args’, 10, 2);

It seems the comma does not work to select the multiple grids that I want to exclude id 2037 from…

Hello There,

You do not use comma in conditions. You will have to separate them. For example;

if ( ($grid_name == 'New Releases Concord Page') || $grid_name == 'New Release RECORDS Page Grid')  ) {

Or you can have if-else-if condition like:

if ( ($grid_name == 'New Releases Concord Page')  ) {
  // your php lines
} elseif ( ($grid_name == 'New Release RECORDS Page Grid') ){
  // your php lines
} else {
  // your php lines
}

Hope this helps.

Thanks, I tried the first suggestion and it broke. I modified to this:

function my_query_args($query_args, $grid_name) {
if ($grid_name == ‘New Releases Concord Page’ || $grid_name == ‘New Release RECORDS Page Grid’) {
// all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
$query_args[‘cat’] = -2037; /11 is the category ID you want to exclude/
}
return $query_args;
}
add_filter(‘tg_wp_query_args’, ‘my_query_args’, 10, 2);

and it works!

Thanks!

You’re welcome, glad we could help.

Cheers!

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