Give_Payment_Stats::get_best_selling PHP Method

get_best_selling() public method

Get the best selling forms
Since: 1.0
public get_best_selling ( $number = 10 ) : array
$number int The number of results to retrieve with the default set to 10.
return array Best selling forms
    public function get_best_selling($number = 10)
    {
        global $wpdb;
        $give_forms = $wpdb->get_results($wpdb->prepare("SELECT post_id as form_id, max(meta_value) as sales\n\t\t\t\tFROM {$wpdb->postmeta} WHERE meta_key='_give_form_sales' AND meta_value > 0\n\t\t\t\tGROUP BY meta_value+0\n\t\t\t\tDESC LIMIT %d;", $number));
        return $give_forms;
    }

Usage Example

Example #1
0
 /**
  * Test Get Best Selling Donation Forms
  *
  * @covers Give_Payment_Stats::get_best_selling
  */
 public function test_get_best_selling()
 {
     $stats = new Give_Payment_Stats();
     $best_selling = $stats->get_best_selling();
     //Best selling should return an array ordered by sale count
     $this->assertLessThan($best_selling[0]->sales, $best_selling[1]->sales);
 }