In a functions.php I use a redirect to show a profile page when a correct code is added to the homepage. It worked before, but ever since a third party coder added some changes it no longer does. I initially added an isset to remove a Undefined index: post_type error. Now there are no more errors, but instead of being redirected to the profile view I am being redirected to the final else statement: a 404. Here is the redirect code:
function my_template_redirect()
{
global $wp;
global $wp_query;
if (isset($_REQUEST['post_type']))
{
if ($_REQUEST['post_type']=="signup")
{
// Let's look for the property.php template file in the current theme
if (have_posts())
{
include(TEMPLATEPATH . '/register.php');
die();
}
else
{
$wp_query->is_404 = true;
}
}else if ($_REQUEST['post_type']=="viewprofile")
{
// Let's look for the property.php template file in the current theme
if (have_posts())
{
include(TEMPLATEPATH . '/viewprofile.php');
die();
}
else
{
$wp_query->is_404 = true;
}
}
}
}
Profile view code is here: http://pastebin.com/1Nkxp0Zv . Form code on home is:
<div class="container">
<form action="<?php echo get_option('home'); ?>/?post_type=viewprofile" method="post">
<span>Enter your code here:</span><input name="enterCodeId" type="text" class="inputBox" /><input type="submit" value="GO!" class="go" />
</form>
</div>
Any ideas why my key is no longer accepted and keep on getting 404-ed via the last else statement?
Looks like the only way to get to that is by not having any posts, or if the have_posts() function returns a falsy value. That’s where you will find your error.