WordPress Rest filter for custom taxonomy gets applied to the admin area

I have a custom taxonomy called collection, with advanced custom fields in it.

I’m using wordpress API, so since I need to filter the API responses by ACF values, I have this filter in my theme functions.php:

add_filter( ‘rest_collection_query’, function( $args ) {
$ignore = array(‘page’, ‘per_page’, ‘search’, ‘order’, ‘orderby’, ‘slug’);
foreach ( $_GET as $key => $value ) {
if (!in_array($key, $ignore)) {
$args[‘meta_query’][] = array(
‘key’ => $key,
‘value’ => $value,
);
}
}
return $args;
});

This works great, except now in the WP admin, my taxonomy checkbox list no longer shows up for the custom post type to which it is registered.

I tried to wrap this block inside if(!is_admin()) {}, but that had no effect. Is there a specific syntax I should be using?

Read more here:: WordPress Rest filter for custom taxonomy gets applied to the admin area

Leave a Reply

Your email address will not be published. Required fields are marked *