From 34aa64950d43b222c0f6588282662913cb9ac9b1 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 8 Oct 2020 11:04:25 +1100 Subject: [PATCH] Fix search suggestions in WordPress Core Force fetchLinkSuggestions() to always set type=post when the JavaScript has been bundled for use in WordPress Core. This is because WordPress Core does not yet have the necesasry PHP to support specifying type=term or type=post-format in /wp/v2/search. --- packages/editor/src/components/provider/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 257ab1adb738b..ceee30ba3ff0c 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -53,6 +53,15 @@ const fetchLinkSuggestions = async ( { isInitialSuggestions, type, subtype, page, perPage: perPageArg } = {}, { disablePostFormats = false } = {} ) => { + // Only allow specifying a type argument in the Gutenberg plugin. This is + // because WordPress Core does not yet support type=term or type=post-format + // when hitting /wp/v2/search. This if() can be removed once the PHP code + // added in https://github.com/WordPress/gutenberg/pull/22600 has been + // committed to WordPress Core. + if ( process.env.GUTENBERG_PHASE === 1 ) { + type = 'post'; + } + const perPage = perPageArg || isInitialSuggestions ? 3 : 20; const queries = [];