diff --git a/assets/js/blocks/attribute-filter/block.tsx b/assets/js/blocks/attribute-filter/block.tsx index 37de98860df..fee90f29668 100644 --- a/assets/js/blocks/attribute-filter/block.tsx +++ b/assets/js/blocks/attribute-filter/block.tsx @@ -130,6 +130,7 @@ const AttributeFilterBlock = ( { resourceName: 'products/attributes/terms', resourceValues: [ attributeObject?.id || 0 ], shouldSelect: blockAttributes.attributeId > 0, + query: { orderby: 'menu_order' }, } ); const { results: filteredCounts, isLoading: filteredCountsLoading } = diff --git a/src/StoreApi/Routes/V1/ProductAttributeTerms.php b/src/StoreApi/Routes/V1/ProductAttributeTerms.php index 5e10d685b82..2bd0e7eb4f7 100644 --- a/src/StoreApi/Routes/V1/ProductAttributeTerms.php +++ b/src/StoreApi/Routes/V1/ProductAttributeTerms.php @@ -46,6 +46,17 @@ public function get_args() { ]; } + /** + * Get the query params for collections of attributes. + * + * @return array + */ + public function get_collection_params() { + $params = parent::get_collection_params(); + $params['orderby']['enum'][] = 'menu_order'; + return $params; + } + /** * Get a collection of attribute terms. * diff --git a/src/StoreApi/docs/product-attribute-terms.md b/src/StoreApi/docs/product-attribute-terms.md index efb4c05552e..397bf04c813 100644 --- a/src/StoreApi/docs/product-attribute-terms.md +++ b/src/StoreApi/docs/product-attribute-terms.md @@ -2,14 +2,14 @@ ```http GET /products/attributes/:id/terms -GET /products/attributes/:id/terms&orderby=slug +GET /products/attributes/:id/terms?orderby=slug ``` -| Attribute | Type | Required | Description | -| :-------- | :------ | :------: | :---------------------------------------------------------------------------- | -| `id` | integer | Yes | The ID of the attribute to retrieve terms for. | -| `order` | string | no | Order ascending or descending. Allowed values: `asc`, `desc` | -| `orderby` | string | no | Sort collection by object attribute. Allowed values: `name`, `slug`, `count`. | +| Attribute | Type | Required | Description | +| :-------- | :------ | :------: | :------------------------------------------------------------------------------------------ | +| `id` | integer | Yes | The ID of the attribute to retrieve terms for. | +| `order` | string | no | Order ascending or descending. Allowed values: `asc`, `desc` | +| `orderby` | string | no | Sort collection by object attribute. Allowed values: `name`, `slug`, `count`, `menu_order`. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1/terms" @@ -43,4 +43,3 @@ curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1/terms" 🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here.](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./src/StoreApi/docs/product-attribute-terms.md) -