| 659 | * Retrieve permalink for search. |
| 660 | * |
| 661 | * @since 3.0.0 |
| 662 | * @param string $query Optional. The query string to use. If empty the current query is used. |
| 663 | * @return string |
| 664 | */ |
| 665 | function get_search_link( $query = '' ) { |
| 666 | global $wp_rewrite; |
| 667 | |
| 668 | if ( empty($query) ) |
| 669 | $search = esc_attr( urlencode(get_search_query()) ); |
| 670 | else |
| 671 | $search = esc_attr( urlencode(stripslashes($query)) ); |
| 672 | |
| 673 | $permalink = $wp_rewrite->get_search_permastruct(); |
| 674 | |
| 675 | if( empty( $permalink ) ) |
| 676 | $permalink = home_url("?s=$search"); |
| 677 | else { |
| 678 | $permalink = str_replace( '%search%', $search, $permalink ); |
| 679 | $permalink = home_url( user_trailingslashit( $permalink, 'category' ) ); |
| 680 | } |
| 681 | |
| 682 | return apply_filters( 'search_link', $permalink, $search ); |
| 683 | } |
| 684 | |
| 685 | /** |