[wp-hackers] URL Query Strings being Preserved

Dan Cameron dan at sproutventure.com
Thu Jul 16 07:24:41 UTC 2009


> I wouldn't
> consider it an error, since it could just as easily be regarded as desired
> behavior.
>    

Yeah, after thinking about it for a bit I realized there's plenty of 
reasoning to have it. One main reason would be to keep querystrings that 
sort persistent when navigating through an archive ( e.g. product 
catalogs ).

I ended up writing a filter that I don't mind anyone improving on:

This way I can specify the query string that should be trimmed and 
preserving any other qs that may be needed.

add_filter('get_pagenum_link', 'my_get_pagenum_link', 1, 2);

function my_get_pagenum_link($url='',$querystring='load') {
     $url = apply_filters('myget_pagenum_link', $url);
     $result = preg_replace('/(.*)(\?|&)' . $querystring . 
'=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
     $result = substr($result, 0, -1);

     return $result;
}


More information about the wp-hackers mailing list