mysql - Custom SQL query to get most viewed posts with images -


I'm trying to write a custom SQL query and can only operate it.

I most will choose the top 10 positions with ideas (see address below)

  SELECT p. *, Pm1.meta_value + Where pm1.post_id = p.ID 0 included as wp_posts the number of times the P left both wp_postmeta PM1 published pm1.meta_key = 'pvc_views' and ( '') and p.post_status p Kpost_type = "post" and views by p.post_password DESC border = '0 order, the 10  

code work up, but I need to add anything query Which also gives image attachment metadata. I tried the code below which is an interior include but I get an error:

  SELECT p *, Wp_posts from Pm1.meta_value + 0 AS visualization P INNER JOIN (SELECT * FROM wp_postmeta WHERE post_id = ID and meta_key = '_wp_attachment_metadata') pm2 LEFT JOIN wp_postmeta pm1 ON1.post_id = p.ID WHERE pm1.meta_key = 'pvc_views' and (publish '') and p.post_status p.post_type = 'post' and views by p.post_password DESC limit 0, 10  = '' command 

anyone can

your query

also, you need to alias available wp_posts table internal query Can you help to write again? Select

  as  below. * Leave pm1.meta_value + on the number, which includes image P interiors pm2.meta_value wp_posts wp_postmeta PM2 seen as 0 (pm2.post_id = p.ID and = '_wp_attachment_metadata' as pm2.meta_key) Wp_postmeta Pml on pm1.post_id = p.ID where pm1.me ta_key = 'pvc_views' and ( 'publish') and p.post_status p.post_type = 'post' and views by p.post_password DESC limit 0, 10  
= '' Order

Comments