However, there is a problem that many sites with a large database like ours must have in the slowness when using the internal link search feature.
Hi @fabinhoalmeida can you please provide more information about the internal link search feature you are referring to? Can you please share a screenshot if possible, you can add it to https://snipboard.io/
Additionally, can you also check the functionality when your site is using a default WP Twenty* theme and with all other plugins deactivated.
Hello thelmachido
First I want to thank you for your attention to my call.
Yes, testing has been done with the default theme active and no plugin active other than the Classic Editor to ensure it is related to this plugin in isolation.
Follow the image for you to check:
https://snipboard.io/Yc9nUm.jpg
Thanks
Hello! If you have a very large database, you may want to try to augment the query to be as efficient as possible. 10up has some great suggestions on how to do that in their Best Practices.
The wp_link_query_args filter gives you access to the query args before the query is made. Give that a try and let us know how it goes!
Hi Ryan,
First of all, I want to thank you for your attention in answering me.
I tested the filter you suggested, but it didn’t work in the Classic Editor. Anyway, I don’t think filtering by post types alone would be enough to speed up link building and delivery in our database of hundreds of thousands of posts.
I currently use a filter to search by post title, which shows very good performance and agility in building links both for searches performed by users on the frontend and for links searched by authors in the Gutenberg editor on the backend, but for some reason the Classic Editor does not yield to the filter and responds slowly.
Below is the filter currently used by us for your analysis:
function __search_by_title_only( $search, &$wp_query )
{
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search =
$searchand = '';
foreach ( (array) $q['search_terms'] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
if ( ! empty( $search ) ) {
$search = " AND ({$search}) ";
if ( ! is_user_logged_in() )
$search .= " AND ($wpdb->posts.post_password = '') ";
}
return $search;
}
add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
Thanks
Hi again!
I have tested the following code in a fresh install of WordPress running only the Classic Editor plugin and it correctly excluded other post types from being displayed via the linking tool. Can you provide more detail on what didn’t work?
add_filter(
'wp_link_query_args',
function( $query ) {
$query['post_type'] = 'page';
return $query;
}
);
This filter expects an array of WP_Query args to be passed so doing any custom database queries will not be possible here. This filter is part of the AJAX callback that can be found here.
-
This reply was modified 3 years, 4 months ago by
Ryan Welcher.
Hi again, Ryan!
Yes, this filter worked fine now. As we have a small amount of pages, it responded quickly to the query. However, if we adjust the filter to ‘post’, the query response slows down as expected.
If we could build a query filter for just the post title that works in the classic editor, we would have a much faster response in our case.
Thank you for your support!