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 1123Notice: Undefined index: offset in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1124Notice: Undefined index: parent in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1140Notice: Undefined index: get in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1144Notice: Undefined index: child_of in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1163Notice: Undefined index: parent in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1164Notice: Undefined index: orderby in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1189Notice: Undefined index: order in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1222Notice: Undefined index: exclude in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1235Notice: Undefined index: exclude_tree in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1236Notice: Undefined index: include in
/var/www/html/wp-merwaa/wp-includes/taxonomy.php on line 1237Notice: 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()
);
}
add_filter('get_terms_defaults','exclude_not_allowed_terms');
1 Answer
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 ) {
if(!current_user_can('edit_others_posts')
&& in_array( 'my-taxonomy', $taxonomies ) ) {
$args['meta_query'] = array(
array(
'key' => 'owner',
'value' => get_current_user_id()
)
);
}
return $args;
}
add_filter( 'get_terms_defaults','exclude_not_allowed_terms', 20, 2 );