Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This will sort posts added to your page with the Elementor Posts widget by
- * rank, assuming that you are assigning reviews to the post_type chosen in the
- * "Query > Source" option of the widget. In order for this to work, you will also
- * need to set the "Query > Query ID" option of the widget to: "sort-by-rank".
- *
- * If you would prefer to sort by rating instead of rank,
- * replace "_glsr_ranking" with "_glsr_average" in the function.
- *
- * @param \WP_Query $query
- * @return void
- */
- add_action('elementor/query/sort-by-rank', function ($query) {
- $query->set('meta_query', [
- 'relation' => 'OR',
- ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
- ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
- ]);
- $query->set('orderby', 'meta_value_num');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement