Level 67
@mozex Should be pretty close...
$query = DB::connection('mysql2')
->table('wpneeds_posts as p')
->select([
'p.ID as id',
'p.post_title as title',
'p.post_name as url',
DB::raw("max(case when m.meta_key = 'preview' then m.meta_value end) as preview"),
DB::raw("max(case when m.meta_key = '_thumbnail_id' then m.meta_value end) as image")
])
->leftJoin('wpneeds_postmeta as m', 'p.ID', 'm.post_id')
->where('p.post_type', 'product')
->where('p.post_status', 'publish')
->whereRaw("(LENGTH(REPLACE(post_content,'\r\n',' ')) - LENGTH(REPLACE(REPLACE(post_content,'\r\n',''), ' ', '')) + 1) < 400")
->groupBy('p.ID')
->get(); // Obviously can use pagination methods instead
You can use toSql() instead of get() to see the query in case I made any typos or anything needs to be adjusted. Using Tinkerwell combined with toSql() is great for building these out.
1 like