Results 1 to 1 of 1
Nov 10, 2011, 12:28 #1
- Join Date
- Nov 2011
- 0 Post(s)
- 0 Thread(s)
Get Comments From Post ID -- SQL method help!
I'll split my question in two parts: First; Am I going about this the right way and Second; See the SQL string below (Any feedback is welcome)
Basically, I have a plugin that pulls content from a post based on a slug wrapped in [[post-title]]. You can then go to a page, insert this shortcode-hybrid syntax directly into the text field, and the page will spit out the content from the selected post ID.
I need to attach the comments from that post to the bottom of the content. I figure there's two ways to attack the problem:
A) use the template_tags
use the $wpdb
I'm using the latter method and I try placing a variable in the SQL string:
WHERE comment_approved = '1' AND comment_post_id='" . $post_id . '"
Unfortunately this does not work.
I have a plugin that I'm trying to add a script that pulls comments based on a post_id
I read somewhere that this script would work but it does not:
$sql = "
SELECT DISTINCT comment_post_ID, comment_author, comment_date_gmt, comment_approved, SUBSTRING(comment_content,1,100) AS com_excerpt
WHERE comment_approved = '1' AND comment_post_id = %s
ORDER BY comment_date_gmt DESC
LIMIT 5", ($post);
$post is defined in another function (in my plugin):
$post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s", $post_name ));
if ( $post ) return get_post($post, $output);
Last edited by alxvallejo; Nov 10, 2011 at 12:50. Reason: Broaden the Question