How to Delete Post and Redirect to another page? (2 posts)

  1. pressup
    Posted 7 years ago #

    I have a plugin that updates the content of a post from other sources, but I want to delete the post if no new content is found. Please look at the code snippet below. I have annotated where I want to have the code [that I can't figure out]. Your help is much appreciated.

    function add_content($content)
        global $post;
        $new_content = get_new_content();
        if ($new_content) {
            // new content available, so update $content
    		$content = $new_content;
        } else {
            // no content, so I want to delete the post
    		$post_ID = $post->ID;
            // Code needed here, having got the post ID
    	//	-> To delete post & associated entries in other tables
            // 	-> And to redirect user to another page
        return $content;
    add_filter('the_content', 'add_content');

    You help would be very much appreciated. Thanking you in advance.


  2. jiltin
    Posted 6 years ago #

    WordPress Experts,

    Is there any solution? I am also looking for similar solution.



Topic Closed

This topic has been closed to new replies.

About this Topic