• I’ve got this problem. I’ve a blog and a plugin that gives the users the users the chance to vote the posts(thumbs up, thumbs down) and the thing is simple: i want to order the posts by the amount of positive votes which are stored on a table on the same DB that WordPress. I tried with the $wpdb object but it didnt work. Hope you can help me out! Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • emm…
    lets first define the $votes in your template, start by zero, then, use a code like this to save new votes:
    update_post_meta($id, ‘_votes’, $votes);

    now you added a the votes count to the database, to retrieve the count, replace the query loop with this query:
    query_posts(‘meta_key=_votes&orderby=meta_value&posts_per_page=5’);

    just like that :), no plugin needed. happy new year…

    Thread Starter xfrancis2

    (@xfrancis2)

    Thanks Khalid but i dont know if i get what youre saying. The plugin is more complex than just a click and update the vote count; it has ip control, ajax to avoid reloading the page and a couple of things more. I cant just replace it by a simple click-vote system if that os what you mean…

    ya you are right, my code is just to replace the $wpdb part, however you still need to solve this other issues.

    Thread Starter xfrancis2

    (@xfrancis2)

    I dont get what “other issues” are you talking about.

    i’m not coder, i just like php, may be i explain it wrongly, so plz forgive me.
    i guess your code should have three parts:
    1. check if the user have voted before, else he can vote.
    2. after user votes you need to update records, and reorder posts.
    3. reorder posts according to votes.

    for me, i thought “update_post_meta($id, ‘_votes’, $votes);” will be much easier than the “$wpdb” route, so i was addressing the third part only.

    Thread Starter xfrancis2

    (@xfrancis2)

    Oh, i get now. Thanks Khalid, but thats not what im looking for.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Order posts by an another table value’ is closed to new replies.