php - How can I have a wordpress post doing 302 redirect on some metadata? -


i writing wordpress plugin adds new post type. post type can have metadata called "redirect". when redirect populated, i'd 302 redirect url written in field, instead of showing post.

i've tried die(), exit(), wp_die() headers() shows "headers sent".

now i'm trying hook "send_headers", @ level don't have post id or post metadata.

any suggestions on hook able proper 302 redirect instead of showing post?

note: not touch theme, plugin can theme-indipendent

thanks

try

add_action( "template_redirect", "callback_function_name");  function callback_function_name(){   global $post;   // https://codex.wordpress.org/conditional_tags  // check single custom post type   if( is_singular("post_typename")){       echo $post->id; // write redirection code here     exit;   }  } 

Comments