Make WordPress Core

Opened 14 years ago

Last modified 5 years ago

#11398 assigned enhancement

new sort method for query_posts (order by last comment date)

Reported by: erdenozkan's profile erden.ozkan Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9
Component: Query Keywords: needs-patch
Focuses: Cc:

Description

I think we need sorting by latest post comment ability for query_posts. "Recent comments" plugins does this but we need this sorting in the core.

BBPress is planned as a WP plugin according latest chat logs posted by Matt. We gonna have to need this anyway.

Attachments (2)

11398.diff (1.0 KB) - added by wonderboymusic 11 years ago.
11398.2.diff (3.2 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (15)

#1 @ryan
14 years ago

  • Milestone changed from 2.9 to 3.0

#2 @Denis-de-Bernardy
14 years ago

  • Keywords needs-patch added; query_posts removed
  • Milestone changed from 3.0 to Future Release

#3 @wojtek.szkutnik
14 years ago

  • Keywords gsoc added

#4 follow-up: @wonderboymusic
11 years ago

  • Keywords has-patch added; needs-patch gsoc removed
  • Milestone changed from Future Release to 3.7

Gonna move this into 3.7 for review. It's actually a pretty easy patch. 11398.diff adds comment_date as an allowed key for orderby:

$posts = get_posts( array( 'fields' => 'ids', 'orderby' => 'comment_date' ) );

The big issue is that it requires a JOIN of posts and comments which won't work if the tables are partitioned or something. This could be an option for the user, but maybe something that core never uses.

#5 @wonderboymusic
11 years ago

updated to LEFT JOIN, my posts_per_page was wrong so I didn't notice the limit was off

#6 @greenshady
11 years ago

  • Cc justin@… added

#7 @wonderboymusic
11 years ago

  • Keywords commit added

.2.diff has Unit Tests - tests revealed the need for:

$orderby = "ISNULL($wpdb->comments.comment_date), $wpdb->comments.comment_date";

#8 in reply to: ↑ 4 @nacin
11 years ago

Replying to wonderboymusic:

The big issue is that it requires a JOIN of posts and comments which won't work if the tables are partitioned or something. This could be an option for the user, but maybe something that core never uses.

WordPress assumes that all blog-level tables are in the same dataset can be joined, including posts, terms, comments, and the associated meta tables. Users is considered a global table, so it cannot be joined with comments, posts, etc. (and is not in core).

#9 @wonderboymusic
11 years ago

hence meta_query all over the B*Press - this is unfortunate

#10 @wonderboymusic
11 years ago

Ideas via @nacin and @jjj in IRC:

  1. sort by comment date
  2. put uncommented posts on the top, on the bottom, or ignore them completely
  3. uncommented posts should instead be sorted by post_date (possible with a CASE clause)
  4. sort by "freshest" - which may mean post_modified?

#11 @helen
11 years ago

  • Keywords commit removed
  • Milestone changed from 3.7 to Future Release

#12 @ryan
10 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#13 @chriscct7
8 years ago

  • Keywords needs-patch added; has-patch removed
Note: See TracTickets for help on using tickets.