Query breaks when using v_orderby and meta_query
-
Hi,
When using ‘v_orderby’ and ‘v_sortby’ in combination with ‘meta_query’, the query breaks.
Check out the following WP Query
$args = array( 'v_sortby' => 'views', 'v_orderby' => 'DESC', 'showposts' => 20, 'meta_query' => array( array( 'key' => 'somekey', 'value' => 'somevalue' ); ) ); $go = new WP_Query( $args );
This gives the following MySQL query:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*, (wp_postmeta.meta_value+0) AS views FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) LEFT JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID WHERE 1=1 AND ( (wp_postmeta.meta_key = 'somekey' AND CAST(wp_postmeta.meta_value AS CHAR) = 'somevalue') ) AND wp_postmeta.meta_key = 'views' GROUP BY wp_posts.ID ORDER BY views desc LIMIT 0, 20
And that query ofcourse gives an error: Not unique table/alias: ‘wp_postmeta’
Any idea how to fix this?
- The topic ‘Query breaks when using v_orderby and meta_query’ is closed to new replies.