Home > front end >  Php beginner - apply filter array/return terms
Php beginner - apply filter array/return terms

Time:10-01

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 I miss?

Best regards, Clément

CodePudding user response:

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 );

CodePudding user response:

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;
}
  • Related