API REST: filtro por idioma en /wp/v2/animals (?lang=es|eu)
- Polylang gratuito no filtra la API REST por idioma: el parámetro «lang» se pasa a la consulta. - MCP: list_animals descarta además las fichas de otro idioma (funciona aunque WordPress aún no esté actualizado). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,7 @@ export function createBilagunServer({ api, publicUrl, remote = false }) {
|
|||||||
params.set('status', includeDrafts ? 'publish,draft,pending' : 'publish');
|
params.set('status', includeDrafts ? 'publish,draft,pending' : 'publish');
|
||||||
if (search) params.set('search', search);
|
if (search) params.set('search', search);
|
||||||
if (species) params.set('species', String(await speciesId(species, language)));
|
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);
|
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 }));
|
return animals.map(({ id, name, wpStatus, profile, translationOf }) => ({ id, name, wpStatus, status: profile?.status, featured: profile?.featured, age: profile?.labels?.age, translationOf }));
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -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). */
|
/* 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 ) {
|
add_filter( 'graphql_post_object_connection_query_args', function ( $args, $source, $input ) {
|
||||||
if ( 'animal' !== ( $args['post_type'] ?? '' ) && array( 'animal' ) !== ( $args['post_type'] ?? '' ) ) {
|
if ( 'animal' !== ( $args['post_type'] ?? '' ) && array( 'animal' ) !== ( $args['post_type'] ?? '' ) ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user