Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active August 5, 2019 12:34
Show Gist options
  • Save esamattis/87909f92b19a216dc7f5b2b6c204ad31 to your computer and use it in GitHub Desktop.
Save esamattis/87909f92b19a216dc7f5b2b6c204ad31 to your computer and use it in GitHub Desktop.
UPDATE! This is now a proper extension https://github.com/valu-digital/wp-graphql-polylang
<?php
/**
* Add dummy query var which causes all languages to be shown
* in the queries.
* See https://github.com/polylang/polylang/blob/2ed446f92955cc2c952b944280fce3c18319bd85/include/query.php#L125-L134
*/
add_filter( 'pll_filter_query_excluded_query_vars', function( $excludes ) {
$excludes[] = 'allLanguages';
return $excludes;
}, 3, 10);
add_filter( 'graphql_input_fields', function( $fields ) {
$fields['lang'] = [
'type' => \WPGraphQL\Types::string(),
'description' => 'Select posts by Polylang language',
];
$fields['allLanguages'] = [
'type' => \WPGraphQL\Types::boolean(),
'description' => 'Show posts regardless of the Polylang language',
];
return $fields;
} );
@esamattis
Copy link
Author

Usage

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment