Skip to content

Instantly share code, notes, and snippets.

@Triloworld
Created September 11, 2023 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Triloworld/9cde5508e34333cfac2fdf5355315e3c to your computer and use it in GitHub Desktop.
Save Triloworld/9cde5508e34333cfac2fdf5355315e3c to your computer and use it in GitHub Desktop.
WP PHP Query into couples ok k=v
$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$path_query = wp_parse_url( $url );
// Language process
$lang = substr( get_bloginfo ( 'language' ), 0, 2 );
$path_query_process = str_replace( '/' . $lang , '' , $path_query['path']);
//Strip slash
$path_query_process = trim( $path_query_process, "/" );
//Into separate keys
$path_query_process = explode('/', $path_query_process);
//Remove type of post
array_shift($path_query_process);
$path_query_process_value = array();
$path_query_process_key = array();
foreach ($path_query_process as $k => $v) {
if ($k % 2 == 0) {
$path_query_process_key[] = $v;
}
else {
$path_query_process_value[] = $v;
}
}
$path_query_process = array_combine($path_query_process_key, $path_query_process_value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment