Forum Moderators: open
what I am doing is collecting comments in one page, without displaying it and I want to display those comments on another wordpress page.
is this possible? I can collect the comments but cant seem to display it on another pose/page
any advice is appreciated.
Just to be clear, you literally mean that you have a page about topic A and you want the comments to show up somewhere else entirely, not associated with that page? Or do you simply want the content page to be free of comments on first view and the comments only appear when someone clicks to see comments? I'm reading this as asking the first question. So....
There may be some API for doing it, but I don't know Wordpress internals well enough (now if it were Drupal...).
Essentially, though, WP has a function in /wp-include/comments.php called get_approved_comments() that is a simple wrapper for a DB request, like so
function get_approved_comments($post_id) {
global $wpdb;$post_id = (int) $post_id;
return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1' ORDER BY comment_date");
}
So basically, you would need to feed that the id of the page where the comments were actually made and then output and format that information on the page you're viewing. This would probably have to be a hard-coded relationship, meaning you would have to put in the specific post id every time you wanted to do this.
If you wanted this somehow automated, you would need to build a new database table that would establish relationships between pages.
I have a page (page a) where I collect the comments and do not display the comments on that one page. but I would like the comments on another page to show from page A onto a new page (page b)
I want to be able to say "if this is page id B then show comment from page A" else no comments