Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link builder arguments - 'wp_link_query_args' filter is ignored #31496

Open
Tracked by #35073
designbuildtest opened this issue May 5, 2021 · 8 comments
Open
Tracked by #35073
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement.

Comments

@designbuildtest
Copy link

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

wp_link_query_args

@skorasaurus skorasaurus added [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement. labels May 5, 2021
@skorasaurus
Copy link
Member

skorasaurus commented May 5, 2021

Similar request at #22288 specifically for filtering taxonomies

@getdave
Copy link
Contributor

getdave commented Sep 23, 2021

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?

@ajtatum
Copy link

ajtatum commented Dec 8, 2022

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.

@msacadem
Copy link

msacadem commented Mar 8, 2023

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.

@getdave
Copy link
Contributor

getdave commented Mar 8, 2023

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.

@Cooky101
Copy link

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.

@misaki-web
Copy link

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.

@eidolonnight
Copy link

Since @getdave mentioned "We could look into this more if there is sufficient interest on this Issue." I wanted to note that gizmo2501 is experiencing issues with linking that could be resolved by the ability to customize results: Linking is prioritising attachments instead of posts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

8 participants