WordPress.org

Making WordPress.org

Ticket #1516: 1516.patch

File 1516.patch, 1000 bytes (added by keesiemeijer, 4 years ago)

Set orderby for searches with pre_get_posts to 'search_orderby_title'

  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

     
    195195                $query->set( 'wp-parser-source-file', str_replace( array( '.php', '/' ), array( '-php', '_' ), $query->query['wp-parser-source-file'] ) );
    196196        }
    197197
    198         // If user has '()' at end of a search string, assume they want a specific function/method.
    199198        if ( $query->is_search() ) {
     199
     200                // Order searches by title first.
     201                $query->set( 'orderby', '' );
     202                $query->set( 'search_orderby_title', 1);
     203
     204                // If user has '()' at end of a search string, assume they want a specific function/method.
    200205                $s = htmlentities( $query->get( 's' ) );
    201206                if ( '()' === substr( $s, -2 ) ) {
    202207                        // Enable exact search