Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
What title will you use for the comments when converted to posts? –  Hansy Schmitt Sep 26 '11 at 15:09
    
I was happy with the title FeedWordPress patched together which was something like "Comment on Postname by Visitorname" –  niftycorp Sep 27 '11 at 0:35
add comment

1 Answer 1

up vote 0 down vote accepted

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 );
        }

    }
share|improve this answer
    
Worked perfectly. Thankyou so much @hansy-schmitt ! I only have 3 points so far but am happy to give them to you if there is a way to do that... –  niftycorp Sep 27 '11 at 4:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.