The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End wordpress database help

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #26839

    Hi all im working on a new theme for my blog and alot of it is going to require some customization of the backend, I am very adapt with php however I fall short when it comes to working with SQL via wordpress so here I am asking for some help.

    With that said heres the issue

    I am in need of creating some custom queries the first is quite simple I am trying to get the most commented on posts by a specific category

    here is what I have so far

    $result = $wpdb->get_results(“SELECT comment_count,ID,post_title FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) WHERE $wpdb->term_relationships.term_taxonomy_id = BLOG ORDER BY comment_count DESC LIMIT 0 , 6”);

    I am in no way familiar with the way wordpress works when it comes to databases so any help pointing me in the right direction would be extremely helpful as I have other plans for the theme that will require more complex queries.

    P.S. the codex pages for wordpress are very un-user friedly so I would prefer other sources if at all possible


    Does the query you posted output some error, or what does it output anyway?
    And exactly what do you want to output; the most commented posts from a specific category as posts I presume? Or perhaps you want to output the comments itself? Or the amount of comments belonging to the most commented posts?


    there are template tags that you can use to do all this. You don’t need to use queries like that. There are also plugins that you can use. Try looking through the codex for useful stuff


    @ all i managed to get it to work thanks for the help with this one

    @ cybershot I try to steer away from plugins as mush as possible because 1. I want it to be completely editable and upgradable by me. Adding more third party code to my theme makes this task even more daunting. 2. Doing this all on my own helps me to broaden my knowledge of wordpress.

    anyway thanks for pointing out the tags work around, I was having a brain fart when attempting this because some of the stuff I am customizing is not so simple.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.