【问题标题】:WordPress redirect always redirects to 404WordPress 重定向总是重定向到 404
【发布时间】:2012-03-04 08:45:14
【问题描述】:

在functions.php 中,当将正确代码添加到主页时,我使用重定向来显示个人资料页面。它以前可以工作,但是自从第三方编码人员添加了一些更改后,它就不再这样做了。我最初添加了一个 isset 来删除 Undefined index: post_type 错误。现在没有更多错误了,但我没有被重定向到配置文件视图,而是被重定向到最后的 else 语句:404。这是重定向代码:

    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;
        }
    }
}
    }

个人资料查看代码在这里:http://pastebin.com/1Nkxp0Zv。主页上的表格代码是:

<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>

任何想法为什么我的密钥不再被接受并继续通过最后一个 else 语句获得 404-ed?

【问题讨论】:

    标签: php wordpress redirect


    【解决方案1】:

    看起来唯一的方法是没有任何帖子,或者如果 have_posts() 函数返回一个虚假值。在那里你会发现你的错误。

    【讨论】:

    • 是的,可能就是这样。所以我需要让用户现在有帖子才能看到个人资料视图。需要以某种方式改变它。确实将帖子值更改为 myaccesskey ,因为这是现在用来生成密钥的内容,但我仍然到达 404。而且,是的,那一定是因为这个用户没有帖子......
    • 对我来说,您似乎应该继续运行 include(...viewprofile.php) 代码并完全删除 else
    • 谢谢。那成功了。我会说这样也应该是安全的,现在即使现在有帖子,我也可以访问用户的个人资料。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2018-08-28
    相关资源
    最近更新 更多