diff --git a/mcp/src/tools.js b/mcp/src/tools.js index 747464c..f1b5a99 100644 --- a/mcp/src/tools.js +++ b/mcp/src/tools.js @@ -74,7 +74,7 @@ export function createBilagunServer({ api, publicUrl, remote = false }) { params.set('status', includeDrafts ? 'publish,draft,pending' : 'publish'); if (search) params.set('search', search); if (species) params.set('species', String(await speciesId(species, language))); - let animals = (await api(`/wp/v2/animals?${params}`)).map(summary); + let animals = (await api(`/wp/v2/animals?${params}`)).map(summary).filter((a) => a.language === language); if (status) animals = animals.filter((a) => a.profile?.status === status); return animals.map(({ id, name, wpStatus, profile, translationOf }) => ({ id, name, wpStatus, status: profile?.status, featured: profile?.featured, age: profile?.labels?.age, translationOf })); })); diff --git a/wp-content/mu-plugins/gure-ametsa/api.php b/wp-content/mu-plugins/gure-ametsa/api.php index ce86d73..419472f 100644 --- a/wp-content/mu-plugins/gure-ametsa/api.php +++ b/wp-content/mu-plugins/gure-ametsa/api.php @@ -336,6 +336,16 @@ add_action( 'graphql_register_types', function () { ) ); } ); +/* REST: «?lang=es|eu» en /wp/v2/animals (Polylang gratuito no filtra la API REST por idioma). */ +add_filter( 'rest_animal_collection_params', function ( $params ) { + $params['lang'] = array( 'type' => 'string', 'enum' => array( 'es', 'eu' ), 'description' => 'Only animals in this language.' ); + return $params; +} ); +add_filter( 'rest_animal_query', function ( $args, $request ) { + $args['lang'] = $request['lang'] ?: ''; + return $args; +}, 10, 2 ); + /* GraphQL: «where: { language, adoptionStatus }» en la consulta de animales («status» ya es el estado de publicación de WordPress). */ add_filter( 'graphql_post_object_connection_query_args', function ( $args, $source, $input ) { if ( 'animal' !== ( $args['post_type'] ?? '' ) && array( 'animal' ) !== ( $args['post_type'] ?? '' ) ) {