wc_query_string_form_fields

Outputs hidden form inputs for each query string variable.

Description

wc_query_string_form_fields( (constant) $values = null, (array) $exclude = array(), (string) $current_key = '', (bool) $return = false ); 

Parameters (4)

0. $values — Optional. (constant) => null
Name value pairs.
1. $exclude — Optional. (array) => array()
Keys to exclude.
2. $current_key — Optional. (string) => ''
Current key we are outputting.
3. $return — Optional. (bool) => false
The return.

Usage

  1. if ( !function_exists( 'wc_query_string_form_fields' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // Name value pairs. 
  5. $values = null; 
  6.  
  7. // Keys to exclude. 
  8. $exclude = array(); 
  9.  
  10. // Current key we are outputting. 
  11. $current_key = ''; 
  12.  
  13. // The return. 
  14. $return = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wc_query_string_form_fields($values, $exclude, $current_key, $return); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function wc_query_string_form_fields( $values = null, $exclude = array(), $current_key = '', $return = false ) { 
  2. if ( is_null( $values ) ) { 
  3. $values = $_GET; 
  4. $html = ''; 
  5.  
  6. foreach ( $values as $key => $value ) { 
  7. if ( in_array( $key, $exclude, true ) ) { 
  8. continue; 
  9. if ( $current_key ) { 
  10. $key = $current_key . '[' . $key . ']'; 
  11. if ( is_array( $value ) ) { 
  12. $html .= wc_query_string_form_fields( $value, $exclude, $key, true ); 
  13. } else { 
  14. $html .= '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />'; 
  15.  
  16. if ( $return ) { 
  17. return $html; 
  18. } else { 
  19. echo $html;