• Resolved ncweb

    (@ncweb)


    Hi WordPress developers !

    I have issues with my admin search, in page dashboard. /wp-admin/edit.php?post_type=page.

    1. When I search something, results are no longer ordered with match in title first, then in content.

    2. When I set the dashboard to show alot of pages (100+) so I can see the parent / children structure more clearly without pagination : I can’t even search for something. Hitting the search button does nothing.

    3. Partially related : recently, some pages are missing from Parent Page under Page attributes. (When you start to type and get a suggestion list to select from). – this could be a question on it’s own.

    The issues seems to occur only in the page dashboard, posts search results are fine.

    Every pages are ordered in a parent / children structure, up to 3-4 childrens. I have 400+ pages.

    The theme is custom, I’m in local dev environment (WAMP), the issue still happens when I deactivate all plugins (Anyway, plugins are : Yoast, ACF PRO, Redirections and Regenerate Thumbnails).

    All my dashboard / custom post types / columns extensions are inserted via include() in functions.php

    Even If I comment every include() – Which concretely means I deactivate all features – the problems still occurs.

    The GET query looks normal.

    /wp-admin/edit.php?s=mysearchquery&post_status=all&post_type=page&action=-1&m=0&seo_filter&readability_filter&paged=1&action2=-1

    If I alter the query like this :

    if ( is_admin() ) {
        add_filter( 'posts_search', 'search_by_title_only', 500, 2 );
    }
    
    function search_by_title_only( $search, $wp_query ) {
        // $wp_query was a reference
        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( $wpdb->esc_like( $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;
    }

    I get only match from title (my problem 1 is solved, but I give up match from content…). And I have the feeling that starting to fix things like that could become a mess. More so if the desired behavior should be the default when installing WordPress.

    Can you help me with tips, impressions, experiences ?

    Thanks alot !
    Best regards,

    • This topic was modified 3 years, 2 months ago by ncweb.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t think default result ordering was ever by where the match occurred, that’s not really how SQL ordering works. I just double checked, the current ordering is first by the menu_order field, which in many cases all pages have the same value. After that, ordering is alphabetical by title.

    There are ways to alter the ordering of results, but all available options are by a certain field, there is not a “best match” sort of ordering available by default. Best match ordering would require an advanced search plugin or some custom coding.

    Search failing to work is likely because the code is timing out due to needing to search through so many records. The default search query isn’t very efficient. When the results page is limited to fewer results, SQL is able to stop after finding enough records to fill the page, so it’s less likely to time out.

    The query that populates dropdown selection fields like the Parent Page field are arbitrarily limited to X number of results to avoid performance issues. When you have pages over this limit, not all possible selections are going to be listed.

    Thread Starter ncweb

    (@ncweb)

    Hi @bcworkz

    Thanks for your answer. I figured out exactly what you said.

    By filtering the search to match only occurence from title, ignoring match in content, my admin dashboard (edit-page) is able to work while showing 150-200 results per page.

    As for the dropdown Parent Page, the problem was not the limitation in number of results. In my example, the title I was searching to set as parent was unique and my search was exact match. Still showing nothing. In quick edit tho, the page appeared. If I get the same problem too much, I’ll just set an input field myself that hooks into ‘save_post’ and set the parent page myself. Don’t know what happens exactly on this one for now.

    I appreciate alot that you took the time,
    And wish you the best !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Admin page search is broken, why ?’ is closed to new replies.