Skip to content

Commit ae63d1b

Browse files
committed
feat(wordpress): support custom query params
1 parent 38bff2a commit ae63d1b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/smooth-backend-wordpress/src/acf/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import axios from 'axios'
22
import qs from 'qs'
33

4-
function getParams({ lang, type, filter }) {
4+
function getParams({ lang, type, query }) {
55
const params = {}
66
if (lang) params.lang = lang
77
if (type) params.type = type
8-
if (filter) params.filter = filter
8+
if (query) Object.assign(params, query)
99
return params
1010
}
1111

1212
function paramsSerializer(params) {
13-
return qs.stringify(params, { arrayFormat: 'brackets' })
13+
return qs.stringify(params, { arrayFormat: 'indices' })
1414
}
1515

1616
export function createClient(baseUrl) {
1717
return {
18-
async getContents({ type, slug, lang, filter }) {
18+
async getContents({ type, slug, lang, query }) {
1919
type = type.toLowerCase()
20-
const params = getParams({ lang, type, filter })
20+
const params = getParams({ lang, type, query })
2121

2222
if (slug) {
2323
params.slug = slug

packages/smooth-backend-wordpress/src/wordpress/plugin/index.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function smooth_create_post_type() {
5959

6060
return $data;
6161
} );
62+
63+
// Enable meta_key to be able to sort items
64+
add_filter( "rest_{$post_type['name']}_query", function ($query_vars, $request) {
65+
$meta_key = $request->get_param('meta_key');
66+
if (isset($meta_key)) {
67+
$query_vars["meta_key"] = $meta_key;
68+
}
69+
return $query_vars;
70+
}, 10, 2);
6271
}
6372
}
6473

0 commit comments

Comments
 (0)