Closed jwegan closed 11 years ago
Thank you so much for your help on this. Just sent an small fix for comments.
No problem, thanks for making the theme in the first place :)
Did anyone else have a problem with the query string breaking comments? This block appears to be stopping the rendering of the comment_template.
<?php
$posts=$wpdb->get_results($wpdb->prepare(
"SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value DESC LIMIT 5",
'_wp-svbtle-kudos'
));
?>
I'm connecting to postgresql which is where I suspect the problem lies but thought I would ask before creating an issue.
@bgadoci thats the peril of using wordpress without MySQL ;). I don't see why postgres would have a problem with the query though since it uses standard syntax. Can you try running the query manually on your DB and see what happens? Also is there any error output either from the wordpress or postgres logs?
Ya I probably need to switch. I've been researching all night and I think I narrowed down the error a bit more. I think the problem is actually coming from here...
<?php foreach ( $posts as $post ) {?>
<li>
<a href="<?php echo get_permalink($post->post_id); ?>">
<h3><?php echo get_the_title($post->post_id); ?></h3>
<p class="link_kudo"><?php echo $post->meta_value; ?></p>
</a>
</li>
<?php }; ?>
Because when I remove that the comments come back. And...here is the oddest, and hopefully the most telling, When I move the <?php comments_template(); ?>
line to above the below block...both comments and Also Read comes in fine. When I move it below this block it won't put comments in the page.
<div>
<h2 id='also-read-title'>Also read...</h2>
<ul id='also-read-items'>
<?php foreach ( $posts as $post ) {?>
<li>
<a href="<?php echo get_permalink($post->post_id); ?>">
<h3><?php echo get_the_title($post->post_id); ?></h3>
<p class="link_kudo"><?php echo $post->meta_value; ?></p>
</a>
</li>
<?php }; ?>
</ul>
</div>
In any case it's not your issues as you said but I thought I would reach out. I'm a ruby/rails/postgres/heroku guy trying to get this sweet set up working in an unfamiliar land! Thanks for you help.
Haha, its the blind leading the blind since I'm a python guy. Well if the line with the db query is working, it might be something else.
Here are a few debugging suggestions: 1) try printing out the $posts object and see what it looks like. It should be an array of up to 5 elements and each element should have a post_id and meta_value. 2) Try taking out the get_permalink 3) change the loop construct, so instead of <?php foreach ( $posts as $post ) {?> user <?php for ($i=0; $i < count($posts); $i++): ?> then change all $post to be $posts[$i] and finally change <?php }; ?> to be <?php endfor; ?>
Let me know what you find.
Thanks, John Egan
On Wed, Jan 2, 2013 at 9:26 PM, Brandon Gadoci notifications@github.comwrote:
Ya I probably need to switch. I've been researching all night and I think I narrowed down the error a bit more. I think the problem is actually coming from here...
<?php foreach ( $posts as $post ) {?>
<?php }; ?> <?php echo get_the_title($post->post_id); ?>
<?php echo $post->meta_value; ?>
Because when I remove that the comments come back. And...here is the oddest, and hopefully the most telling, When I move the <?php comments_template(); ?> line to above the below block...both comments and Also Read comes in fine. When I move it below this block it won't put comments in the page.
Also read...
In any case it's not your issues as you said but I thought I would reach out. I'm a ruby/rails/postgres/heroku guy trying to get this sweet set up working in an unfamiliar land! Thanks for you help.
— Reply to this email directly or view it on GitHubhttps://github.com/gravityonmars/wp-svbtle/pull/124#issuecomment-11835333.
So implementing your third recommendation seems to fix the error but it limits the array to one item.
Was just doing simple sort on value, which was wrong since value was a varchar. Decided to sort first on char_length then on value rather than a cast in order to keep query cross-db compatible.