| 659 | * Retrieve permalink for search. |
| 660 | * |
| 661 | * @since 3.0.0 |
| 662 | * @param string $query Optional. The query string to link to uses current query if empty. |
| 663 | * @return string |
| 664 | * use home_url |
| 665 | */ |
| 666 | function get_search_link( $query = '' ) { |
| 667 | global $wp_rewrite; |
| 668 | |
| 669 | if ( empty($query) ) |
| 670 | $search = get_search_query(); |
| 671 | else |
| 672 | $search = stripslashes($query); |
| 673 | |
| 674 | $permalink = $wp_rewrite->get_search_permastruct(); |
| 675 | |
| 676 | if ( empty( $permalink ) ) { |
| 677 | $permalink = home_url('?s=' . urlencode($search) ); |
| 678 | } else { |
| 679 | $search = urlencode($search); |
| 680 | $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, Pre-encode it so its double-encoded. |
| 681 | $permalink = str_replace( '%search%', $search, $permalink ); |
| 682 | $permalink = home_url( user_trailingslashit( $permalink, 'search' ) ); |
| 683 | } |
| 684 | |
| 685 | return apply_filters( 'search_link', $permalink, $search ); |
| 686 | } |
| 687 | |
| 688 | /** |