'Apply filter array/return terms

I would like to apply a filter on which taxonomies are displayed in a widget. I'm close but I think I don't have the correct spelling for it and I'm surely missing something :

add_filter( 'uael_posts_tax_filter', function( $terms ) {
   array('video-genres') // Modify the array here.
  return $terms;
}, 10, 2 );

What is missing?



Solution 1:[1]

Finally I resolve my issue. The code I was given and gave to you was just the beggining. Here the code in order to reach my goal :

add_filter( 'uael_posts_tax_filter', function( $terms ) {
$new_terms = array();
foreach ( $terms as $index => $tax ) {
    if( 'video-genres' === $tax->taxonomy ) { 
        $new_terms[] = $tax;
    }
}
return $new_terms; }, 10, 2 );

Thanks for your help and hope this could help someone in the futur. Best regards, Clément

Solution 2:[2]

Where it says

modify the array here

it means to modify the $terms array so it would contain only the terms you're aiming for.

And not just setting an array.

I'm not sure which plugin this is and how they have set their filters, but this one should work:

add_filter( 'uael_posts_tax_filter', function( $terms ) {

   $terms[] = 'video-genres';
  return $terms;
}, 10, 2 );

Solution 3:[3]

Is this what you're looking for?

add_filter('uael_posts_tax_filter', 'custom_uael_posts_tax_filter', 10, 2);
function custom_uael_posts_tax_filter($terms)
{
    // Modify the array here.
    if ($terms) {
        $terms[] = 'video-genres';
    }

    return $terms;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Clément
Solution 2 Ofir Baruch
Solution 3