|
 |
|
ขอความช่วยเหลือเรื่องการทำ Redirect Url Search ใน Wordpress ให้สามารถค้นหาได้ทั้ง EN และ TH |
|
 |
|
|
 |
 |
|
โอเคตอนนี้ได้แล้วครับ
แก้ที่ nice search จาก โค้ดเดิม LINE : 28
Code (PHP)
<?php
/*
Plugin Name: Nice Search
Version: 0.5
Plugin URI: http://txfx.net/wordpress-plugins/nice-search/
Description: Redirects ?s=query searches to /search/query, and converts %20 to +
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
function cws_nice_search_redirect() {
global $wp_rewrite;
if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
return;
$search_base = $wp_rewrite->search_base;
if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
exit();
}
}
add_action( 'template_redirect', 'cws_nice_search_redirect' );
// Hotfix for http://core.trac.wordpress.org/ticket/13961 for WP versions less than 3.5
if ( version_compare( $wp_version, '3.5', '<=' ) ) {
function cws_nice_search_urldecode_hotfix( $q ) {
if ( $q->get( 's' ) && empty( $_GET['s'] ) && is_main_query() )
$q->set( 's', urldecode( $q->get( 's' ) ) );
}
add_action( 'pre_get_posts', 'cws_nice_search_urldecode_hotfix' );
}
เป็น
Code (PHP)
<?php
/*
Plugin Name: Nice Search
Version: 0.5
Plugin URI: http://txfx.net/wordpress-plugins/nice-search/
Description: Redirects ?s=query searches to /search/query, and converts %20 to +
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
function cws_nice_search_redirect() {
global $wp_rewrite;
if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
return;
$search_base = $wp_rewrite->search_base;
if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
exit();
}
}
add_action( 'template_redirect', 'cws_nice_search_redirect' );
// Hotfix for http://core.trac.wordpress.org/ticket/13961 for WP versions less than 3.5
if ( version_compare( $wp_version, '3.5', '<=' ) ) {
function cws_nice_search_urldecode_hotfix( $q ) {
if ( $q->get( 's' ) && empty( $_GET['s'] ) && 1 )
$q->set( 's', urldecode( $q->get( 's' ) ) );
}
add_action( 'pre_get_posts', 'cws_nice_search_urldecode_hotfix' );
}
|
ประวัติการแก้ไข 2013-05-29 11:56:16
 |
 |
 |
 |
Date :
2013-05-29 11:55:42 |
By :
ppanchai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-05-29 12:00:52 |
By :
cookiephp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|