Leave a Reply

1 comment

  1. You need to provide the alias of wp_posts’s table in the inner query also you can rewrite your query as below

    SELECT 
    p.*, 
    pm1.meta_value + 0 AS viewcount ,
    pm2.meta_value AS image
    FROM wp_posts p
    INNER JOIN 
    wp_postmeta   pm2
     ON (pm2.post_id = p.ID AND pm2.meta_key = '_wp_attachment_metadata')
    LEFT JOIN wp_postmeta pm1  ON pm1.post_id = p.ID
    WHERE 
    pm1.meta_key = 'pvc_views' 
    AND p.post_status IN ('publish') 
    AND p.post_type='post' 
    AND p.post_password ='' 
    ORDER BY viewcount 
    DESC LIMIT 0, 10