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:
I get a fatal error: unexpected ',' on that last line...
$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):
Thanks for your help!
$post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s", $post_name ));
if ( $post ) return get_post($post, $output);