Skip to content

Instantly share code, notes, and snippets.

@shishirraven
Created January 24, 2022 00:45
Show Gist options
  • Save shishirraven/0045230a8913737c1ed02a671c757cb5 to your computer and use it in GitHub Desktop.
Save shishirraven/0045230a8913737c1ed02a671c757cb5 to your computer and use it in GitHub Desktop.
Add meta your meta field to the allowed values of the REST API orderby parameter
$post_type ="wf_account";
// Add meta your meta field to the allowed values of the REST API orderby parameter
add_filter(
'rest_' . $post_type . '_collection_params',
function( $params ) {
$fields = ["first_name","last_name","address","email"];
foreach ($fields as $key => $value) {
$params['orderby']['enum'][] = $value;
}
return $params;
},
10,
1
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment