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:
@@ -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'] ?? '' ) ) {
|
||||
|
||||
Reference in New Issue
Block a user