Home » Documentation » What is PeoplePods? » SDK Documentation » Stacks


PeoplePods handles lists of objects using a special type of object called a Stack. Stacks give you the ability to query people, content, groups, comments and files, then manipulate the results in various ways.

PeoplePods provides a bunch of pre-defined stacks such as $Person->favorites() and $Content->comments(). You can also create new stacks using the stack constructor functions: $POD->getPeople(), $POD->getContents(), $POD->getComments(), and $POD->getGroups().

All of these functions take a very similar set of parameters:

$people = $POD->getPeople($conditions,$sort,$count,$offset);

$posts = $POD->getContents($conditions,$sort,$count,$offset);

$groups = $POD->getGroups($conditions,$sort,$count,$offset);

$comments = $POD->getComments($conditions,$sort,$count,$offset);

$conditions is an associative array of conditions that the objects must meet to be included in the stack. PeoplePods will attempt to link in related information based on what conditions are passed in. Read about creating these conditions.

$sort is a SQL-style sort statement. You can sort by any of the fields in the object, or by any fields in related objects linked in to the query.

$count is the number of objects you want to return.

$offset is the number of objects the stack should pass over before returning results. This allows you to page your results.

To create a stack of recent content, you might use:

$recent = $POD->getContents(array('type'=>'post'),'date DESC',20,0);

Once you've got your stack set up, you can do all sorts of fun things with it:

// see how many items you have in your stack
$count = $recent->count();

// see how many total items match your conditions
$totalCount = $recent->totalCount();

// sort by any field, including meta fields.

// see if another 'page' of results exists:
if ($recent->hasNextPage()) {
  // print out next page link

// use a while loop to iterate over the items
while ($post = $recent->getNext()) {

// reset the contents

// use a foreach loop to iterate over the items
foreach ($recent as $post) { 

// reset again!

// forget iterating, and just output everything

// extract an array of the values of one specific field
$friend_ids = $person->friends()->extract('id');

Stacks do a ton of behind the scenes work for you to make things as efficient and easy to use as possible. For example, if a stack stumbles upon a piece of content that the current user does not have access to (such as content with friends_only or group_only privacy), it will automatically skip the record and find another to replace it. This frees you from considering privacy settings when loading content, while ensuring that you'll always get the right number of results back.

Stacks use a technique called lazy loading to make sure that the data you need is ready when you need it, but not until then. What this means is, you can set up a stack without actually loading information from the database. The database will only be accessed when the stack data is accessed for the first time.

This allows PeoplePods to always offer the pre-defined stacks like $Person->friends() without causing unnecessary database hits when you aren't using them. They're always available, but will only leap into action when called upon.

This also allows you to define a stack, and never actually access it's data, but to access some of its properties:

// set up a stack containing my followers
$followers = $POD->getPeople(array(

// now, access the totalCount function without 
// actually loading the records from the db
echo $followers->totalCount();

More about this function and it's related functions:

  • Discuss This Document

No comments have been posted yet.

Download Download the latest version of PeoplePods!

0.7 Latest Version:
Release Notes

A free membership is required to download PeoplePods.

  Already Registered? Login

Recent Posts from Our Blog

Version 0.7 Now Available

Last night, I uploaded a new release of PeoplePods: version 0.7. The most exciting new features in this version are: new dynamic image resizing options, a faster comment polling system, new ways...

Developer Preview Launch!

I am very excited to announce the launch of PeoplePods version 0.666, THE DEVELOPER PREVIEW! After tons of hacking, I have tweaked the last line of code, and I am finally ready for a wider audience...

Recent Posts from The Forum