Created
December 29, 2021 16:47
-
-
Save lepittenger/0823a3bc57b55805ed21fe82469637a2 to your computer and use it in GitHub Desktop.
Conditional Orderby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$order = ''; | |
if ( sort_group = 1 ) { | |
$order = 'ASC'; | |
} | |
if ( sort_group = 1 ) { | |
$order = 'DESC'; | |
} | |
$args = array( | |
'orderby' => 'meta_value_num', | |
'meta_key' => 'start_date', | |
'order' => $order; | |
); | |
$query = new WP_Query( $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm doing this via
pre_get_posts()
and here is what my current query looks like:I'm also looking at https://developer.wordpress.org/reference/hooks/posts_orderby/ as a possible option, but that's not getting me any closer just yet.
Really appreciate your input.