Skip to content

Instantly share code, notes, and snippets.

@mvaneijgen
Created August 12, 2019 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvaneijgen/a642acd244b48c46316178cbdd6493a3 to your computer and use it in GitHub Desktop.
Save mvaneijgen/a642acd244b48c46316178cbdd6493a3 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'graphql_PostObjectsConnectionOrderbyEnum_values', function( $values ) {
$values['FEATURED'] = [
'value' => 'featured',
'description' => __( 'Get only featured items', 'wp-graphql' ),
];
return $values;
} );
add_filter( 'graphql_post_object_connection_query_args', function( $query_args, $source, $input ) {
if ( isset( $input['where']['orderby'] ) && is_array( $input['where']['orderby'] ) ) {
foreach( $input['where']['orderby'] as $orderby ) {
if ( ! isset( $orderby['field'] ) || 'featured' !== $orderby['field'] ) {
continue;
}
$query_args['meta_key'] = 'featured';
$query_args['meta_value'] = true;
}
}
return $query_args;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment