Thursday, January 26, 2023
HomeWordPress Developmentposts - WP_Query - The way to add a second INNER JOIN...

posts – WP_Query – The way to add a second INNER JOIN for extra advanced ORDER BY?


Hiya WordPress neighborhood,

on the whole you should utilize meta_query within the attribute record of WP_Query to construct up a ORDER BY utilizing the MySQL CAST() perform. That is fairly useful however involves a restrict as quickly as I prefer to order by 2 meta keys.

What WordPress does ist construct up a mt1 INNER JOIN on wp_postmeta like:

INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
WHERE (mt1.meta_key = 'my_custom_key')

they usually present a numeric sorting on that with:

ORDER BY CAST(mt1.meta_value AS SIGNED) ASC

IS there an official approach the add a mt2 line comparable as meta_query does or do I actually should go together with a customized $wpdb->get_col() to achive such a customized approach of ordering?

Notice: I find out about 'relation' => 'OR' in meta_query however that solely creates extra circumstances for mt1 as an alternative of making a brand new mt2 JOIN.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments