Last active
January 4, 2016 20:39
-
-
Save tomkrush/8675537 to your computer and use it in GitHub Desktop.
add query vars to page num link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function edg_get_pagenum_link_query_vars($query_vars) { | |
$query_vars['test'] = 'asdf'; | |
return $query_vars; | |
} | |
add_filter('get_pagenum_link_query_vars', 'edg_get_pagenum_link_query_vars'); | |
function parse_query($var) | |
{ | |
$var = parse_url($var, PHP_URL_QUERY); | |
$var = html_entity_decode($var); | |
$var = explode('&', $var); | |
$arr = array(); | |
foreach($var as $val) | |
{ | |
$x = explode('=', $val); | |
$arr[$x[0]] = $x[1]; | |
} | |
unset($val, $x, $var); | |
return $arr; | |
} | |
function edg_get_pagenum_link($result) | |
{ | |
$query_vars = parse_query($result); | |
list($result) = explode('?', $result, 2); | |
$query_vars = apply_filters('get_pagenum_link_query_vars', $query_vars); | |
if ( count($query_vars) ) | |
{ | |
$query_string = ''; | |
foreach($query_vars as $key => $var) { | |
$query_string .= $key.'='.urlencode($var); | |
} | |
$result .= '?'.$query_string; | |
} | |
return $result; | |
} | |
add_filter('get_pagenum_link', 'edg_get_pagenum_link'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment