Created
August 12, 2019 15:36
-
-
Save MjHead/9ff98a46b85229aff460fa95324606ff to your computer and use it in GitHub Desktop.
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
<?php | |
add_filter( 'jet-engine/listing/grid/posts-query-args', 'je_custom_listing_order', 10, 2 ); | |
/** | |
* Add multiple order by paramters to listing grid widget. | |
* | |
* What you need t replace: | |
* - speakers_list - replace this with your custom ID added to Listing widget | |
* - is-featured, speaker-name - meta fields names we need to sort by. | |
* - featured_clause, name_clause - your custom keys for order clauses | |
* | |
*/ | |
function je_custom_listing_order( $args, $widget ) { | |
// We need to add custom CSS ID to listing widget, to ensure we modifying correct query | |
$id = $widget->get_settings( '_element_id' ); | |
if ( 'speakers_list' === $id ) { | |
// Then we need to add apropriate meta fields into meta_query argument | |
$args['meta_query'] = array( | |
'relation' => 'AND' , | |
'featured_clause' => array( | |
'key' => 'is-featured', | |
'compare' => 'EXISTS', | |
), | |
'name_clause' => array( | |
'key' => 'speaker-name', | |
'compare' => 'EXISTS', | |
), | |
); | |
// And then set order by these fields. | |
$args['orderby'] = array( | |
'featured_clause' => 'DESC', | |
'name_clause' => 'ASC', | |
); | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment