Friday, January 25, 2013

cara merubah search parameter di wordpress

taruh kode ini di function.php
// Add this code to your functions.php file in your active theme folder
 
  1. // Allow WordPress to access "search" in the query string
  2. function ds_whitelist_new_search_parameter( $allowed_query_vars ) {
  3.  $allowed_query_vars[] = 'search';
  4.  return $allowed_query_vars;
  5. }
  6. add_filter('query_vars', 'ds_whitelist_new_search_parameter' );
  7.  
  8.  
  9. // populate s parameter with value of search
  10. function ds_swap_search_parameter($query_string) {
  11.  
  12.  $query_string_array = array();
  13.  
  14.  // convert the query string to an array
  15.  parse_str($query_string, $query_string_array);
  16.  
  17.  // if "search" is in the query string
  18.  if(isset($query_string_array['search'])){
  19.   $query_string_array['s'] = $query_string_array['search']; // replace "s" with value of "search"
  20.   unset($query_string_array['search']); // delete "search" from query string
  21.  }
  22.  
  23.  return http_build_query($query_string_array, '', '&'); // Return our modified query variables
  24. }
  25. add_filter('query_string', 'ds_swap_search_parameter');

No comments:

Post a Comment