Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Custom orderby param value #2265

Closed
Youdaman opened this issue Feb 11, 2016 · 2 comments
Closed

Custom orderby param value #2265

Youdaman opened this issue Feb 11, 2016 · 2 comments
Labels

Comments

@Youdaman
Copy link

Hi, I've got some logic in my pre_user_query and pre_get_posts that lets me use a custom value with the orderby query param.

In the latest update there's a breaking change that limits the valid request args to an enum set, and I understand I have to use rest_validate_request_arg somehow to allow my custom orderby value.

I don't know where/how to do this however, and if you could point me to the right filter or snippet that lets me merge my value with the defaults that would be great!

@Youdaman
Copy link
Author

I managed to work out how to slot in my custom orderby param ("honey") as follows:

add_filter('rest_endpoints', 'my_modify_rest_routes');
function my_modify_rest_routes( $routes ) {
  array_push( $routes['/wp/v2/topic'][0]['args']['orderby']['enum'], 'honey' );
  array_push( $routes['/wp/v2/users'][0]['args']['orderby']['enum'], 'honey' );
  //error_log('routes = ' . print_r($routes, true));
  return $routes;
}

Hope this helps anyone else having the same issue since the breaking change.

@danielbachhuber
Copy link
Member

In the latest update there's a breaking change that limits the valid request args to an enum set, and I understand I have to use rest_validate_request_arg somehow to allow my custom orderby value.

Sorry about that :( It skipped my mind that anyone would be using a custom orderby value.

I'll make sure we get the "extending routes" aspect documented WP-API/docs-v2#114

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants