如果帖子处于草稿状态,请重定向


Redirect if a post is in draft status

>我有两种自定义帖子类型,分别是"项目"和"项目-won"。如果用户转到处于草稿状态的单个"项目",我希望他们被重定向到相应的"项目赢得"帖子。

每个帖子都将在两种帖子类型之间复制,因此,如果有一个具有以下 URL 的"项目":
mydomain.com/?project=test-project/,那么这将是带有 URL 的"项目获胜":mydomain.com/?project-won=test-project/。

我可以在"单个项目.php"模板页面的顶部放置一些内容吗?

<?php if($post->post_status  == "draft"){ 
    //add the redirect here

我不知道最好的方法是什么?

First of all define global variable $post.
than check the if loop.
global $post;
if( $post->post_status == 'draft' ) {
/* Your Redirect code Here */
}
Try this code may your problem be solved by defining global variable $post.
 global $post;
    if( $post->post_status == 'draft' && is_singular('project') ) {
    wp_redirect( <the_url>, 301 ); 
    }

您需要替换为代码才能查找自定义帖子类型的分类。你可以从中得到一些帮助

希望这有帮助。