Last active
August 5, 2019 12:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage