WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. pressup
    Member
    Posted 6 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.

    <?php
    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.

    Jason

  2. jiltin
    Member
    Posted 5 years ago #

    WordPress Experts,

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

    Thanks,

    Jiltin

Topic Closed

This topic has been closed to new replies.

About this Topic