Esempio n. 1
0
 /**
  * @param $post_types
  * @param $search_term
  * @param int $current_page
  *
  * @param $sort
  *
  * @return mixed
  */
 public function get_plan_items_by_type($post_types = '', $search_term = '', $current_page = 0, $sort = null)
 {
     global $wpdb;
     if ($current_page == 0) {
         $current_page = $this->current_page;
     } else {
         $this->current_page = $current_page;
     }
     if (empty($post_types)) {
         $post_types = ForestOptions::get_instance()->default_plan_item_post_types();
     }
     $where = $this->get_post_types_where($post_types, $search_term);
     if (is_wp_error($where)) {
         return 0;
     }
     if (isset($sort)) {
         $sort = $sort->sort_col_id . ' ' . $sort->sort_dir;
     } else {
         $sort = 'modified DESC';
     }
     $limit = ' LIMIT ' . $this->item_per_page . ' OFFSET ' . ($current_page - 1) * $this->item_per_page;
     $sql = "SELECT SQL_CALC_FOUND_ROWS p.ID, p.post_title, p.post_status, p.post_date, p.post_author, p.post_type\n\t             \tFROM " . $this->table_name . " p2ps " . "JOIN " . $wpdb->prefix . "posts p " . "ON p2ps.child_id = p.ID " . "WHERE p2ps.parent_id = " . $this->plan_id . " AND " . $where . "ORDER BY " . $sort . $limit;
     ForestHelperSingleton::get_instance()->write_log($sql);
     $this->items = $this->select($sql);
     //get posts
     $this->rows_found = $this->get_var('SELECT FOUND_ROWS()');
     //get over all rows(pagination)
     $this->max_num_pages = ceil($this->rows_found / $this->item_per_page);
     //calc overall number of pages(pagination)
     return $this->format_items();
 }
 public function __construct()
 {
     $this->table_name = '';
     $this->current_page = 1;
     $this->item_per_page = ForestOptions::get_instance()->get_items_per_page();
     $this->max_num_pages = 0;
     $this->rows_found = 0;
     $this->items = [];
     $this->clear_errors();
 }
Esempio n. 3
0
 public function google_api_key()
 {
     return ForestOptions::get_instance()->get_google_api_key();
 }
 /**
  * TODO: access the plan system options to get default types
  * @return array
  */
 private function default_post_types()
 {
     return ForestOptions::get_instance()->default_plan_item_post_types();
 }