ap_parse_search_string( string $str )
Description #
Parse search string to array.
Parameters #
- $strstring (Required) search string.
Source #
File: includes/functions.php
function ap_parse_search_string( $str ) { $output = array(); // Split by space. $bits = explode( ' ', $str ); // Process pairs. foreach ( $bits as $id => $pair ) { // Split the pair. $pair_bits = explode( ':', $pair ); // This was actually a pair. if ( count( $pair_bits ) === 2 ) { $values = explode( ',', $pair_bits[1] ); $sanitized = array(); if ( is_array( $values ) && ! empty( $values ) ) { foreach ( $values as $value ) { if ( ! empty( $value ) ) { $sanitized[] = sanitize_text_field( $value ); } } } if ( count( $sanitized ) > 0 ) { // Use left part of pair as index and push right part to array. if ( ! empty( $pair_bits[0] ) ) { $output[ sanitize_text_field( $pair_bits[0] ) ] = $sanitized; } } if ( isset( $bits[ $id ] ) ) { // Remove this pair from $bits. unset( $bits[ $id ] ); } } else { // Exit the loop. break; } } // Rebuild query with remains of $bits. $output['q'] = sanitize_text_field( implode( ' ', $bits ) ); return $output; }
Expand full source code Collapse full source code View on GitHub: includes/functions.php:1009
Add your comment