0

I have two custom post types called 'project' and 'project-won'. If a user goes to a single 'project' that is in draft status, I want them to be redirected to the corresponding 'project-won' post.

Each post will be replicated across both post types, so if there was a 'project' that had the following URL:
mydomain.com/?project=test-project/ , then ther would be a 'project-won' with the URL: mydomain.com/?project-won=test-project/.

Can I just put something at the top of the 'single-project.php' template page such as

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

I don't know what the best way to do this would be?

TheCloudlessSky
  • 18,608
  • 15
  • 75
  • 116
user537137
  • 606
  • 2
  • 10
  • 23

2 Answers2

0
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.
Arvind Pal
  • 543
  • 4
  • 15
0
 global $post;
    if( $post->post_status == 'draft' && is_singular('project') ) {
    wp_redirect( <the_url>, 301 ); 
    }

You need to replace with a code to find taxonomy of your custom post type. You can take some help from this

Hope this helps.

Community
  • 1
  • 1
Sid
  • 115
  • 1
  • 10