-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Comments
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 Unfortunately I don't think we can simply add in the 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: 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. |
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 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 +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. |
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 |
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
The text was updated successfully, but these errors were encountered: