| | |
| | | } |
| | | if (subtype === 'taxonomy') { |
| | | // Assumes taxonomy rest_base matches the (unprefixed) taxonomy slug. |
| | | return (search) => addQueryArgs(`/wp/v2/${field.taxonomy}`, { search, per_page: 20 }); |
| | | return (search) => addQueryArgs(`/wp/v2/${field.taxonomy}`, { search, per_page: 20, hide_empty: false }); |
| | | } |
| | | return (search) => addQueryArgs('/wp/v2/search', { search, type: 'post', subtype: field.post_type, per_page: 20 }); |
| | | }; |
| | |
| | | |
| | | // Resolve current IDs to labels on mount / value change |
| | | useEffect(() => { |
| | | onInputChange(''); |
| | | let cancelled = false; |
| | | if (!ids.length) { |
| | | setTokens([]); |
| | |
| | | |
| | | const onInputChange = useCallback((search) => { |
| | | setSearch(search); |
| | | if (!search) { setOptions({}); return;} |
| | | |
| | | apiFetch({ path: buildPath(search) }) |
| | | .then((results) => { |
| | |
| | | if (isSingle) { |
| | | onChange(newIds[newIds.length - 1] ?? 0); |
| | | } else { |
| | | onChange(field.max ? newIds.slice(0, field.max) : newIds); |
| | | onChange((field.max ? newIds.slice(0, field.max) : newIds).join(',')); |
| | | } |
| | | }; |
| | | |