hanuman6
7/13/2013 - 11:50 AM

検索設定

検索設定

add_action( 'posts_search', 'enable_empty_query', 10, 2 );
function enable_empty_query( $search, $wp_query ) {
    global $wpdb;

    if ( $wp_query->is_main_query() ) {
        if ( isset( $_REQUEST['s'] ) && empty( $_REQUEST['s'] ) ) {
            $term = $_REQUEST['s'];
            $wp_query->is_search = true;
            if ( $term === '' ) {
                $search = ' AND 0';
            } else {
                $search = " AND ( ( $wpdb->posts.post_title LIKE '%{$term}%' ) OR ( $wpdb->posts.post_content LIKE '%{$term}%' ) )";
            }
        }
    }
    return $search;
}