How to batch convert comments to posts?

I want to display comments using a Post slider plugin, but comments aren't posts.

I had a dodgy setup with FeedWordPress (sydnication plugin) by sucking the Comments RSS feed in to to the Comments into Posts, but the RSS feed has mysteriously stopped updating. So I'm thinking it might be better to find a way to convert Comments into Posts in a different way.

I took a look at some post-type switchers, but didn't see any that considered Comments to be a post-type.

Any tips would be much appreciated. Thanks in advance!

Topic switch post-type rss comments Wordpress

Category Web


You can copy this code into a plugin and when activated will convert all comments into posts, and delete the comments (so you will not have duplicates)

You can also limit what kind of comments will be converted the posts using the parameters for get_comments ( http://codex.wordpress.org/Function_Reference/get_comments )

    register_activation_hook( __FILE__, 'wpse_29474_convert_to_posts' );
    function wpse_29474_convert_to_posts(){
        $comments = get_comments();

        foreach($comments as $comment) 
        {

            $post=get_post($comment->comment_post_ID);
            $title=sprintf("Comment on %s by %s",$post->post_title,$comment->comment_author);
            $content=$comment->comment_content;
            $my_post = array(
                 'post_title' => $title,
                 'post_content' => $content,
                 'post_status' => 'publish',
                 'post_author' => 1
            );      
           wp_insert_post( $my_post );
           wp_delete_comment( $comment->comment_ID );
        }

    }

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.