Exclude Custom Taxonomy from The Grid

Hi i use the grid to display post and custom post type (video) all my post and CPT use category and publisher (a custom taxonomy) i would like to exclude certain publisher form my grid :

this is the code i use but when it execute my page where the grid is displaying saying (no post was found)

function my_query_args($query_args, $grid_name) {
if ($grid_name == 'Spotrise Basic Grid') {
    // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
    $query_args['publisher'] = -56; /*11 is the category ID you want to exclude*/
}
return $query_args;

}
add_filter(ā€˜tg_wp_query_args’, ā€˜my_query_args’, 10, 2);

Hey There,

Thanks for writing in! The query_args is only good for the default category. Since you are using a custom taxonomy, your code should have pointed out that ā€œpublisherā€ is a custom taxonomy. Please check out this code as your point of reference: https://wordpress.stackexchange.com/a/263866

Thank you for your understanding.

Ok thank you for trying to help me. But I’m sorry im bad in english and in web dev. Can you indicate me properly what I need to write.

I want to do the same thing that exclude a category using the ID of the cat but for ā€œpublisherā€ who is a custom taxonomy.

Sorry for the repetition.

Hey There,

You may use this code:

function my_query_args($query_args, $grid_name) {
  if ($grid_name == 'Spotrise Basic Grid') {
      // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
      $query_args = array(
          'tax_query'      => array(
              array(
                  'taxonomy' => 'publisher',
                  'operator' => 'NOT EXISTS'
              )
          )
      );
  }
  return $query_args;
}
add_filter('tg_wp_query_args', 'my_query_args', 10, 2);

Hope this helps.

1 Like

Thank you but is not totally correct. I paste my code here to let others see it if they need to do the same thing.

function my_query_args($query_args, $grid_name) {
  if ($grid_name == 'Spotrise Basic Grid') {
      // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
      $query_args = array(
          'tax_query'      => array(
              array(
                  'taxonomy' => 'publisher',
				  'terms' => array('42'),
				  'field' => 'ID',
                  'operator' => 'NOT IN'
              )
          )
      );
  }
  return $query_args;
}
add_filter('tg_wp_query_args', 'my_query_args', 10, 2);

Great! We are just glad that you have figured it out a way to correct the said issue.
We appreciate for letting us know!

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