Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#5108 closed enhancement (fixed)

More wrapper functions for direct queries

Reported by: Viper007Bond Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3
Component: General Keywords:
Focuses: Cc:


I need to get the number of comments awaiting moderation. Apparently the only way to do this is a direct SQL query:

$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'" );

The problem with this is forwards compatibility (what if the structure of the table is changed?) as well as more complex code.

I propose common queries such as approved comments, spam comments, comments in moderation, all comments, etc. be wrapped into functions that return the data. That way the function can be updated with no ill effects or changes to the code.

This could be applied to post queries as well.

Simply put, the less direct querying, the better IMO.

Change History (4)

#1 follow-up: @westi
8 years ago

+1 this sounds like a really good idea.

The more plugin have an API to use rather than direct SQL the better.

#2 @ffemtcj
8 years ago

  • Milestone changed from 2.5 to 2.7

No Patch. Moved to 2.7

#3 in reply to: ↑ 1 @jqs
8 years ago

So we are looking to build as many wrappers as possible? Can you give me a list of data you'd like and I'll start writing them...
Do you want them direct as your example or possibly with options for getting data from a specific category etc?

#4 @ryan
8 years ago

  • Keywords needs-patch removed
  • Milestone changed from 2.7 to 2.5
  • Resolution set to fixed
  • Status changed from new to closed

This is fixed in 2.5 with the addition of wp_count_comments().

Note: See TracTickets for help on using tickets.