• Hello guys,

    Hello guys,

    I’m using the classic editor because I find it more practical. 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. Gutenberg works very well in this regard. I’ve already tried to limit the search only by words in the title of the posts to improve performance through code in functions.php, but it only worked for the frontend, thus serving only the search made by readers in searches on public pages, it had no effect on the search built-in classic editor. Is there any way to improve the performance of this function? I hope they can help me in some way. Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    Thread Starter fabinhoalmeida

    (@fabinhoalmeida)

    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!

    Thread Starter fabinhoalmeida

    (@fabinhoalmeida)

    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 1 year, 9 months ago by Ryan Welcher.
    Thread Starter fabinhoalmeida

    (@fabinhoalmeida)

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Internal Link Search’ is closed to new replies.