Open designbuildtest opened 3 years ago
Similar request at #22288 specifically for filtering taxonomies
I understand the motivation behind this request. Thank you for taking the time to raise it.
Currently, the items shown the new Link UI are retrieved from the v2/search
REST API endpoint.
Unfortunately I don't think we can simply add in the wp_link_query_args
into that API endpoint because it would be out of context.
If we agree that adding backwards compatibility for this feature is required, then we might need to introduce a sort of "Proxy" endpoint for "Link search" (eg: WP_REST_Link_Search_Controller
). We can then start to support filters such as wp_link_query_args
whilst still proxying the ultimate request to the WP_REST_Search_Controller
endpoint.
I'd like to get some other opinions on this. Perhaps @spacedmonkey and @hellofromtonya would be able to advise further?
Without the ability to filter the results, this "feature" is useless on my site as a portion of my site is content aggregation (a custom post type) so whenever I try to link to my own content, it pretty much never comes up in the auto suggest... I have to manually insert the URL of the page. So, being able to filter the post type would be a game changer.
Without the ability to filter the results, this "feature" is useless on my site as a portion of my site is content aggregation (a custom post type) so whenever I try to link to my own content, it pretty much never comes up in the auto suggest... I have to manually insert the URL of the page. So, being able to filter the post type would be a game changer.
Yes, very true. I don't know how more complex sites (with many post types) deal with this. Searching for a link is a hassle currently. We have many post types that should not be linkable but they all show up when trying to find a post to link to. It's time-consuming and prone to errors.
The current implementation in Gutenberg uses JavaScript to query various API endpoints to get the search results. This makes it difficult to customise with PHP. Not ideal as many of you have pointed out and also inefficient.
Interestingly I've experiment a bit with creating a REST API endpoint which calls _WP_Editors::wp_link_query
. We could look into this more if there is sufficient interest on this Issue.
I appreciate this is frustrating but there are a limited number of contributors to work on things.
I agree with the previous comments, that the current solution is just unusable. I have a plugin in use that manages affiliate links and creates a CPT for them, and that a) avoids relevant suggestions to come up, b) is very slow in providing results and c) is even more painful, as it starts searching as soon as you type the first characters. So if you want to search for something like "scooter" it will start searching e.g., at "sc" and when you're done typing the entire word, the results for "sc" finally show, but are completely cluttered with irrelevant stuff that happens to contain "sc" somehow. Then you have to remove the last character again, to trigger yet another search.
So +1 from my side on solving this in a more user-friendly way, and at least adding the ability to filter CPTs from showing in the results.
Indeed, the lack of customization in the list of links suggested by Gutenberg can be problematic, especially for sites with multiple custom post types. I've published a Gist that demonstrates how the REST API's WP_REST_Search_Controller can be customized as a workaround if such customization is urgently needed. You can find the example here: https://gist.github.com/misaki-web/95a3f5f13bf0534d64e18b43602e2139
Of course, as I specify in the Gist, editing core files should be avoided, and these changes will be overwritten with WordPress updates. This is meant to serve as a demonstration or a temporary solution until a more permanent fix is implemented.
Description
Using the classic editor, it's possible to exclude post types and taxonomies from appearing in the link builder using:
function my_custom_link_query( $query ){
$query['post_type'] = array( 'post', 'pages', 'snippets' );
return $query;
}
add_filter( 'wp_link_query_args', 'my_custom_link_query' );
Gutenberg does not appear to support this same level of filtering of link builder arguments. All post types and taxonomies are available as link options by default.
Expected behaviour
Feature parity with classic editor enabling the filtering of link builder arguments.
Actual behaviour
All post types and taxonomies are available, even when filters are applied via wp_link_query_args
Screenshots