get() публичный статический Метод

Returns a post or posts based on supplied parameters.
public static get ( array $paramarray = [] ) : Posts | Post | string
$paramarray array An associative array of parameters, or a querystring. The following keys are supported: - id => a post id or array of post ids - not:id => a post id or array of post ids to exclude - slug => a post slug or array of post slugs - not:slug => a post slug or array of post slugs to exclude - user_id => an author id or array of author ids - content_type => a post content type or array post content types - not:content_type => a post content type or array post content types to exclude - status => a post status, an array of post statuses, or 'any' for all statuses - year => a year of post publication - month => a month of post publication, ignored if year is not specified - day => a day of post publication, ignored if month and year are not specified - before => a timestamp to compare post publication dates - after => a timestamp to compare post publication dates - month_cts => return the number of posts published in each month - criteria => a literal search string to match post content or title - title => an exact case-insensitive match to a post title - title_search => a search string that acts only on the post title - has:info => a post info key or array of post info keys, which should be present - all:info => a post info key and value pair or array of post info key and value pairs, which should all be present and match - not:all:info => a post info key and value pair or array of post info key and value pairs, to exclude if all are present and match - any:info => a post info key and value pair or array of post info key and value pairs, any of which can match - not:any:info => a post info key and value pair or array of post info key and value pairs, to exclude if any are present and match - vocabulary => an array describing parameters related to vocabularies attached to posts. This can be one of two forms: - object-based, in which an array of Term objects are passed - any => posts associated with any of the terms are returned - all => posts associated with all of the terms are returned - not => posts associated with none of the terms are returned - property-based, in which an array of vocabulary names and associated fields are passed - vocabulary_name:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, any of which can be associated with the posts - vocabulary_name:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, any of which can be associated with the posts - vocabulary_name:not:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, none of which can be associated with the posts - vocabulary_name:not:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, none of which can be associated with the posts - vocabulary_name:all:term => a vocabulary name and term slug pair or array of vocabulary name and term slug pairs, all of which must be associated with the posts - vocabulary_name:all:term_display => a vocabulary name and term display pair or array of vocabulary name and term display pairs, all of which must be associated with the posts - on_query_built => a closure that accepts a Query as a parameter, allowing a plugin to alter the Query for this request directly - limit => the maximum number of posts to return, implicitly set for many queries - nolimit => do not implicitly set limit - offset => amount by which to offset returned posts, used in conjunction with limit - page => the 'page' of posts to return when paging, sets the appropriate offset - count => return the number of posts that would be returned by this request - orderby => how to order the returned posts - groupby => columns by which to group the returned posts, for aggregate functions - having => for selecting posts based on an aggregate function - where => manipulate the generated WHERE clause. Currently broken, see https://trac.habariproject.org/habari/ticket/1383 - add_select => an array of clauses to be added to the generated SELECT clause. - fetch_fn => the function used to fetch data, one of 'get_results', 'get_row', 'get_value', 'get_query' Further description of parameters, including usage examples, can be found at http://wiki.habariproject.org/en/Dev:Retrieving_Posts
Результат Posts | Post | string An array of Post objects, or a single post object, depending on request
Пример #1
0
 /**
  * Output a post collection based on the provided parameters.
  *
  * @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
  */
 public function get_collection($params = array())
 {
     // Store handler vars since we'll be using them a lot.
     $handler_vars = Controller::get_handler_vars();
     // Retrieve the current matched rule and store its name and argument values.
     $rr = URL::get_matched_rule();
     $rr_name = $rr->name;
     $rr_args = $rr->named_arg_values;
     // Assign alternate links based on the matched rule.
     $alternate_rules = array('atom_feed_tag' => 'display_entries_by_tag', 'atom_feed' => 'display_home', 'atom_entry' => 'display_entry', 'atom_feed_entry_comments' => 'display_entry', 'atom_feed_page_comments' => 'display_entry', 'atom_feed_comments' => 'display_home');
     $alternate_rules = Plugins::filter('atom_get_collection_alternate_rules', $alternate_rules);
     $alternate = URL::get($alternate_rules[$rr_name], $handler_vars, false);
     // Assign self link based on the matched rule.
     $self = URL::get($rr_name, $rr_args, false);
     // Get posts to put in the feed
     $page = isset($rr_args['page']) ? $rr_args['page'] : 1;
     if ($page > 1) {
         $params['page'] = $page;
     }
     if (!isset($params['content_type'])) {
         $params['content_type'] = Post::type('entry');
     }
     $params['content_type'] = Plugins::filter('atom_get_collection_content_type', $params['content_type']);
     $params['status'] = $this->is_auth() ? 'any' : Post::status('published');
     $params['orderby'] = 'updated DESC';
     $params['limit'] = Options::get('atom_entries');
     $params = array_merge($params, $rr_args);
     if (array_key_exists('tag', $params)) {
         $id = urlencode($params['tag']);
         $tags = explode(' ', $params['tag']);
         foreach ($tags as $tag) {
             if ($tag[0] == '-') {
                 $tag = substr($tag, 1);
                 $params['vocabulary'][Tags::vocabulary()->name . ':not:term'][] = Utils::slugify($tag);
             } else {
                 $params['vocabulary'][Tags::vocabulary()->name . ':all:term'][] = Utils::slugify($tag);
             }
         }
         unset($params['tag']);
     } else {
         $id = 'atom';
     }
     $posts = Posts::get($params);
     if (count($posts)) {
         $updated = $posts[0]->updated;
     } else {
         $updated = null;
         header('HTTP/1.1 404 Not Found', true, 404);
         die('Posts could not be found');
     }
     $xml = $this->create_atom_wrapper($alternate, $self, $id, $updated);
     $xml = $this->add_pagination_links($xml, $posts->count_all());
     $xml = $this->add_posts($xml, $posts);
     Plugins::act('atom_get_collection', $xml, $params, $handler_vars);
     $xml = $xml->asXML();
     ob_clean();
     header('Content-Type: application/atom+xml');
     print $this->tidy_xml($xml);
 }