Created
January 24, 2022 00:45
-
-
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
This file contains hidden or 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
$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