Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- if(cm.comment_approved = '1' and cm.user_id > 0, cm_u.display_name, ps_u.display_name) as display_name,
- cm.comment_author,
- a.title as title,
- if(cm.comment_approved = '1', cm.comment_ID, pst.ID) as post_id,
- if(cm.comment_approved = '1', cm.user_id, pst.post_author) as author_id,
- a.max_post_date as post_date,
- if(cm.comment_approved = '1', SUBSTRING(cm.comment_content, 1, 200), SUBSTRING(pst.post_content, 1, 200)) as content,
- if(cm.comment_approved = '1', 'comment', pst.post_type) as type,
- if(pst.post_type = 'reply', ifnull(pst.post_parent,0), pst.ID) as post_parent
- from (
- SELECT
- if(p.post_type = 'reply', t.post_title, p.post_title) as title,
- if(com.comment_approved = '1', unix_timestamp(com.comment_date), unix_timestamp(p.post_date)) as post_date,
- if(p.post_type = 'reply', ifnull(p.post_parent,0), p.ID) as post_parent,
- max(if(com.comment_approved = '1', unix_timestamp(com.comment_date), unix_timestamp(p.post_date))) as max_post_date,
- max(if(com.comment_approved = '1', com.comment_ID, p.ID)) as max_post_id
- FROM `wp_posts` as p
- LEFT JOIN `wp_posts` as t on t.ID = p.post_parent
- LEFT JOIN `wp_comments` as com on com.comment_post_ID = p.ID
- WHERE ((p.post_type = 'reply' OR p.post_type = 'topic' OR p.post_type = 'post')
- AND p.post_status = 'publish'
- AND p.post_content <> '')
- OR com.comment_approved = '1'
- group by post_parent) a
- LEFT JOIN `wp_posts` as pst on a.max_post_id = pst.id
- LEFT JOIN `wp_comments` as cm on a.max_post_id = cm.comment_post_ID
- LEFT JOIN `wp_users` as cm_u on cm_u.ID = cm.user_id
- LEFT JOIN `wp_users` as ps_u on ps_u.ID = pst.post_author
- order by max_post_date desc
- limit 0,12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement