Hi,
Sorry to resurrect such an old thread...
I'm trying to run a function to alter the post_type in my wordpress query string (or to add a post type altogether). The function I'm using comes from here: http://www.addedbytes.com/blog/code/php-querystring-functions/
Based on Halojoy's example, I've written this:
<?php //add query to URL
function add_querystring_var($url, $key, $value) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
return ($url . '&' . $key . '=' . $value);
}
}
?>
<?php
if (isset($_GET['run'])) $linkchoice=$_GET['run'];
else $linkchoice='';
switch($linkchoice){
case 'showAll' :
add_querystring_var($url, 'post_type', '');
break;
case 'showAnimation' :
add_querystring_var($url, 'post_type', 'animation');
break;
case 'showPeople' :
add_querystring_var($url, 'post_type', 'people');
break;
case 'showStudios' :
add_querystring_var($url, 'post_type', 'studios');
break;
case 'showResources' :
add_querystring_var($url, 'post_type', 'resources');
break;
case 'showWiki' :
add_querystring_var($url, 'post_type', 'wiki');
break;
default : ;
}
?>
<h2>Show... </h2>
<a href="?run=showAll">All</a>
<a href="?run=showAnimation">Animation</a>
<a href="?run=showPeople">People</a>
<a href="?run=showStudios">Studios</a>
<a href="?run=showResources">Resources</a>
<a href="?run=showWiki">Wiki</a>
When I click any of these links, they take me to "mywebsite.com/?run=showX" - which in turn directs me to my front page. I think this means that the function is not running, and I'm wondering if anyone has any suggestions as to why. I've tried testing without the function, and with just echoes indicating that a function has ran, instead - and these haven't done anything. I am still directed to the url indicated in the link and nothing beyond that seems to happen. Have I set the function to run incorrectly?
Thanks in advance!