Home » Documentation » Creating Stack Condition Parameters

Creating Stack Condition Parameters

A lot of the magic sauce in PeoplePods comes from the way stacks are created. By passing in the right set of conditions, you can generate a stack of almost any description.

You can pass in one or more conditions to a stack constructor. Each condition is a key/value pair where the key is one of the PeoplePods fields, and the value is single value or an array of values that the field must match.

Let's look at an easy example. This code will create a stack of content objects where the type field is set to 'post':

$posts = $POD->getContents(array('type'=>'post'));

If we wanted to load content where the type field was one of a couple options, we could pass in an array instead of the single value:

$types = array('post','event','video');

If we wanted to load content where the type field was NOT equal to a value, we could add one of the stack condition operators to the key side of the condition, after a ":"

// load content that is NOT of the type 'status'
$stuff = $POD->getContents(array('type:!=','status'));

(It is also possible to use an operator when passing in an array of values.)

Multiple Conditions

Several conditions in this format can be chained together to form more complex queries. All of the conditions you set are required to be met for inclusion in the stack. (In SQL speak, we're ANDing the conditions.)

Here's another example. This code will create a stack that contains all the content of type 'post' that was created by the current user:

$my_posts = $POD->getContents(array(

If PeoplePods was english, that would say "Give me content that is a posts AND is authored by me."

As above, you can also pass in arrays of values in combination with other fields. The following example would load content from the first 2 users in the database:

$users = array(1,2);
$posts = $POD->getContents(array(

A practical example of the above uses one of the pre-defined stacks and the handy $Stack->extract() function (which returns an array) to create a stack of the most recent content that was created by anyone in the current user's friend list, with a SINGLE COMMAND:

$friend_content = $POD->getContents(array(

It is possible to pass in any number of conditions, though you probably won't ever need more than 2 or 3.

Different Types of Stacks

In addition to content, stacks are also used to manage lists of people, groups, comments and files. Just be careful to use the correct field names in your condition list: for example, the 'headline' field is only available when doing a $POD->getContents() call, whereas the 'groupname' field is only available when doing a $POD->getGroups() call. If you call getGroups() with a headline parameter, you will probably break everything.

The fields you can use are listed on the various object definition pages: Person Object, Content Object, Group Object.

Most of the time, if you aren't loading content and you aren't using one of the pre-defined relationship stacks, you're doing a search by keyword.

Let's take a look at a few examples:

// search the members by nickname
$sresults = $POD->getPeople(array('nick:like'=>"%foo%"));

// search the groups by groupname
$sresults = $POD->getGroups(array('nick:like'=>"%foo%"));

Linked Information

All the examples we've seen so far assume you are running a pretty simple query directly on one of the base content types: a list of content by content type, a list of people by their names. Sometimes, however, you will want to set conditions on related pieces of information: the author of a post, or the owner of a group, for example.

To do this, you preface the foreign field name with a short code representing that relationship. For example, the code below will dynamically link in the user table to give us access to the content's author record so that we can check the author's name:

$posts = $POD->getContents(array(

We might also want to reference the group a piece of content is in. This example loads content that has been added to a public group:

$posts = $POD->getContents(array(

Similarly, you might reference a flag. The following code will create a stack of content where the 'awesome' flag has been set:

$posts = $POD->getContents(array(

Referencing Meta Fields

You can reference meta fields as if they were native fields. You can access meta fields of the object you are querying, and also in the linked objects. You can also reference multiple meta fields - PeoplePods will automatically build the database queries required to link together all the tables.

But be careful! The more meta fields and cross-linking you introduce into your stack, the more complicated the database query will be. This can lead to slow queries.

// load content where the meta field 'foo' is set to 'bar'
$posts = $POD->getContents(array(

// load content where the meta field 'foo' is set to 'bar' and the there is a value for another meta field called 'baz'
$posts = $POD->getContents(array(

// load content from users who have a meta field called 'super' has the value 1
$superposts = $POD->getContents(array(

There's more about using meta fields and flags in this way on their respective pages.

Each type of object has different relationships you can reference. Here they are, in list form:

In calls to $POD->getContents():

  • a. - reference fields in the content's author record (userId)
  • o. - reference fields in the content's creator/owner record (creatorId)
  • g. - reference fields in the content's group record if one exists
  • p. - reference fields in the content's parent content record if one exists
  • f. - reference files connected to this content
  • c. - reference comments connected to this content
  • t. - reference tags connected to this content
  • flag. - reference the content's flags.

Some examples:

// load content where author's name is 'chester'
$content = $POD->getContents(array('a.nick'=>'chester'));

// load content where the author has a meta field named 'featured'
$featured = $POD->getContents(array('a.featured:'1'));

// load content where the parent content does not have a parent
$second_level = $POD->getContents(array('p.parentId'=>'null'));

In calls to $POD->getPeople():

  • d. - reference content authored by this user
  • c. - reference comments by a user
  • f. - reference files uploaded by a user
  • flag. - reference the person's flags
  • g. - reference a group that a person is a member of
  • mem. - reference the membership record only

Some examples:

//get a list of people who are adminUsers
$admins = $POD->getPeople(array('adminUser'=>'1'));

// get a list of people who have been flagged 'trouble'
$trouble = $POD->getPeople(array('flag.name'=>'trouble'));

// get a list of people are in a group
$members = $POD->getPeople(array(

// get a list of people who are managers of a group
$managers = $POD->getPeople(array(

// get a list of people who have uploaded an avatar
$pictures = $POD->getPeople(array('f.file_name'=>'img'));

In calls to $POD->getGroups():

  • o. - reference the group's owner
  • u. - reference the group's members
  • d. - reference content in the group
  • flag. - reference the group's flags
  • mem. = reference the groups membership records

Some examples:

// get groups where the current user is a member
$my_groups = $POD->getGroups(array(

// get groups where $person has been invited
$invites = $POD->getGroups(array(

// get groups where that contain featured content
$featured = $POD->getGroups(array(

In calls to $POD->getComments():

  • a. - reference comment's author
  • u. - reference comment's author
  • d. - reference comment's parent content

In calls to $POD->getFiles():

  • u. - reference files's owner
  • d. - reference files's parent content if one exists

In calls to $POD->getTags():

  • d. - reference tag's linked content
  • tr. - reference just the tag relationship (for access to just contentId)
  • 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...