-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow to sort/order by custom metabox fields #39
Comments
I'm sure it's possible. Let me take a look. It's been a while since I worked on this so hopefully we're not too out of date. |
hey man, thanks for the reply. i since figured out how to make a custom field orderable, but since i don't really have any php experience i didnt yet have time to figure out how to do it programmatically. anyway here is the code i use to make one field orderable: $field_id = 'my_custom_field'
// register field for ordering
add_filter('graphql_PostObjectsConnectionOrderbyEnum_values',
function ($values) use ($field_id) {
$values[strtoupper($field_id)] = [
'value' => $field_id,
'description' => __('my custom description', 'wp-graphql'),
];
return $values;
}
);
// make orderable
add_filter('graphql_post_object_connection_query_args',
function ($query_args, $source, $input) use ($field_id) {
$orderby_inputs = $input['where']['orderby'];
if (isset($orderby_inputs) && is_array($orderby_inputs)) {
foreach ($orderby_inputs as $orderby) {
if (!isset($orderby['field']) || $field_id !== $orderby['field']) {
continue;
}
$query_args['meta_key'] = $field_id;
$query_args['orderby'] = 'meta_value meta_value_num';
$query_args['order'] = $orderby['order'];
}
}
return $query_args;
}, 10, 3
); |
That is super helpful. I am quite good with PHP these days, so I can use that to add to the plugin. I am moving homes at the moment, but I hope to take a look soon. |
hey, thanks for the awesome plugin!
would it be possible to allow graphql to sort / order by custom fields?
thanks in advance
The text was updated successfully, but these errors were encountered: