..and in my sidebar I have a recent posts widget. In that I get via $wpdb->show_errors();

WordPress database error: [You have an
error in your SQL syntax; check the
manual that corresponds to your MySQL
server version for the right syntax to
use near 'voted > 1 ORDER BY
wp_posts.post_date DESC LIMIT 0, 5' at
line 1] SELECT SQL_CALC_FOUND_ROWS
wp_posts.* FROM wp_posts LEFT JOIN
wp_vote_posts ON wp_posts.ID =
wp_vote_posts.vote_post_id WHERE 1=1
voted > 1 ORDER BY wp_posts.post_date
DESC LIMIT 0, 5

I noticed WHERE 1=1 voted > 1.. not sure if that's causing the error and how to fix it.

Is there a reason you really needed a separate table? Why not use custom fields (postmeta?)
–
MikeSchinkelNov 28 '10 at 17:01

@MikeSchinkel the custom field table has too much data and will create too many rows for voting. My separate table is more clean and organized.
–
wpStudentNov 28 '10 at 21:10

Are you logging votes, or just creating a running total? If the former, I agree another table but I'd still consider maintaining the running total in custom fields, even on a per-option basis so up to 5 custom fields per post if you are using a 1..5 rating. Or you could store in one custom field as an array, but they could could do a join across posts for all posts where vote=5, for example. Otherwise if you use SQL to count the votes each time you'll end up with a very poorly performing site (I know this from specific experience related to a voting plugin I wrote.)
–
MikeSchinkelNov 28 '10 at 23:36

1 Answer
1

instead of hardcoding table names you should use $wpdb->prefix . 'post_votes';

instead of checking in global $_GET you should declare your filters as accepting two arguments and code functions accordingly, these filters pass as second argument object that contains all of query data.

Thank you Rarst!! It works now :) I don't understand your second note. I have to check if the URL parameter exists to use the filter. How can I implement the two arguments you provided?
–
wpStudentNov 27 '10 at 23:32

Your URL parameters are parsed and stored in query object, which you can access inside your function via passed $query variable in my example above. Just try var_dump( $query ); to see everything that it contains, your custom arguments should be in there as well if used.
–
Rarst♦Nov 27 '10 at 23:35

I'm very sorry Rarst, I still don't fully understand. Can you please share an example?
–
wpStudentNov 27 '10 at 23:47

Updated answer with more written out example.
–
Rarst♦Nov 27 '10 at 23:53

Ooh I see. Thanks! I tried the code, no errors.. but nothing happens. All posts are displayed regardless of the URL paramater
–
wpStudentNov 28 '10 at 0:06