Advertisement
geminilabs

[site-reviews] sort posts by rank with Elementor Pro

Jan 13th, 2020
362
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * This will sort posts added to your page with the Elementor Posts widget by
  3.  * rank, assuming that you are assigning reviews to the post_type chosen in the
  4.  * "Query > Source" option of the widget. In order for this to work, you will also
  5.  * need to set the "Query > Query ID" option of the widget to: "sort-by-rank".
  6.  *
  7.  * @param \WP_Query $query
  8.  * @return void
  9.  */
  10. add_action('elementor/query/sort-by-rank', function ($query) {
  11.     $query->set('meta_query', [
  12.         'relation' => 'OR',
  13.         ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
  14.         ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
  15.     ]);
  16.     $query->set('orderby', 'meta_value_num');
  17. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement