Tuesday, February 8, 2022

[FIXED] Wordpress: How to redirect a post to an another post?

Issue

I have searched a lot, and only thing i found is wp_redirect(). To use that function, I need to edit the files in the site. But i want to use only one file to communicate with my wordpress site. So, is there any other way to redirect a post from an additional php file like this:

redirect_post_to_link($post_id, $link);

I have tried (the first method that comes to mind) updating the post content to <meta http-equiv="refresh" content="0;URL=https://www.examplewpsite.com/postblabla"> with

include("wp-load.php")
$post = get_post( $post_id );
$post->post_content = $redirect_code
$update_output = wp_update_post( $post );
if($update_output != 0){ // ...code continues...

but it doesn't actually update the post, when you visit the post you get blank content.

sorry if i asked a incorrect question.


Solution

I just found how to solve this. removing filter during update progress by kses_remove_filters() makes me update the content whatever i want.



Answered By - aphelios

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.