I've failed to filter hook get_terms_defaults, I got this notices and it won't to load any term

Notice: Undefined index: number in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1123

Notice: Undefined index: offset in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1124

Notice: Undefined index: parent in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1140

Notice: Undefined index: get in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1144

Notice: Undefined index: child_of in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1163

Notice: Undefined index: parent in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1164

Notice: Undefined index: orderby in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1189

Notice: Undefined index: order in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1222

Notice: Undefined index: exclude in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1235

Notice: Undefined index: exclude_tree in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1236

Notice: Undefined index: include in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1237

Notice: Undefined index: childless in /var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1269

My code

public function exclude_not_allowed_terms() {
  if(!current_user_can('edit_others_posts')) {
    $args['meta_query'] = array(
      'key'       => 'owner',
      'value'     => get_current_user_id()

1 Answer 1


Filters are for modifying data that's passed through them. You need to take the input, modify it, then return it.

function exclude_not_allowed_terms( $args, $taxonomies ) {
      && in_array( 'my-taxonomy', $taxonomies ) ) {
        $args['meta_query'] = array(
                'key'    => 'owner',
                'value'  => get_current_user_id()
    return $args;
add_filter( 'get_terms_defaults','exclude_not_allowed_terms', 20, 2 );
  • Now there's no notices, but the function doesn't work, terms isn't filtered by the meta
    – Maometto
    Feb 1, 2016 at 21:19
  • I've two meta(s) in the DB term_id meta_key meta_value 24 owner 2 23 owner 1
    – Maometto
    Feb 1, 2016 at 21:21
  • meta query should be an array of arrays, edited above.
    – Milo
    Feb 1, 2016 at 21:23
  • How can I specific this filter for special taxonomy?
    – Maometto
    Feb 1, 2016 at 21:36
  • I edited it to check taxonomy, not sure it's right. $taxonomies is the second argument passed to the filter, it's an array of taxonomies that were passed to get_terms. you also have to adjust add_filter to pass 2 arguments.
    – Milo
    Feb 1, 2016 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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