Pods CMS: setting up a status field

When you write posts or pages in WordPress, there’s already a setting for status:

the status box in wordpress

This is pretty straightforward to set up with Pods CMS for your pods content, by using input and pre-save helpers.

First, install the helper called Selectbox Your Values. Copy the code from the link and “import” it using the Pods CMS Package Manager.

Go to your WordPress Admin > Pods > Package Manager:

Once you hit “Proceed to Confirmation” you should see a “Success!” and “Finalize” message (not necessarily in that order).

After that, you have to do a quick edit to the helper, so go to Pods > Setup > Input Helper:

Edit your input helper

Change the code as shown in bold:

<?php
$arr = array("waiting for approval", "published"); //array with fixed values, edit and/or add these with your preferences
?>
<select id="<?php echo $css_id; ?>">

<?php
 foreach ($arr as $val) {
 if ($val==$value) { $selected="selected"; } else { $selected=""; } // add selected argument to set value
 echo '<option value="' . $val . '" ' . $selected . '>' . $val . '</option>';
 }
?>
</select>

Then, create a column in your pod called status, and then add the input helper that you just installed and modified:

Now, if this field hasn’t been made a “required field” you can create a pre-save helper so that your default status becomes “waiting for approval“. This is useful if you are making a public form where you won’t be showing the status column as an option.

Go to your WordPress Admin > Pods > Setup > Helpers and add a new helper:

For the code, just add the following:

<?php
if($columns['status']['value']==undefined)
{
$columns['status']['value'] = 'waiting for approval';
}
?>

All this code above does is check the value of your status column. If it’s undefined (because your user hasn’t used the drop-down menu at all) it sets the value of the status column to ‘waiting for approval’.

After that, just go to your pod settings and add this pre-save helper:

To display only the pods content with a status of published, use the following code

$name-of-your-pod-goes-here = new Pod('name-of-your-pod-goes-here');
 $params['select'] = '*';
 $params['orderby'] ='t.name ASC'; // sorts by the name, optional
 $params['where'] = 'status = "Published"';
 $name-of-your-pod-goes-here ->findRecords($params);

Pods: simple way to loop through and display a multi-select field

if ($my-multi-select-field)
{
     foreach($my-multi-select-field as $item)
         {
               echo $item['name'];
          }
}

Here’s another thing I discovered (thanks to Stack Overflow): sometimes you’ll want to loop through your field and display it like:

item, item, item

Minus the comma at the end. To do that, just use this snippet:

echo implode(", ", array_map(create_function('$item', 'return $item["name"];'), $my-multi-select-field));

Pods CMS: how to relate a pod to WordPress taxonomy

Thanks to Scott Clark I figured out how to create a pod with a column that relates to WordPress Categories:

The above image demonstrates how to create a multi-select to choose multiple categories to associate with my pod.

Because category is a PICK field, it has to be reference with the syntax:

category.name

Say, if you want to select all pods content with a category name of  “my-category” with a link like this:

http://my-domain-here.com/category/my-category/

You can get the “my-category” part of the link above with the code:

$selected = pods_url_variable(-1);

And then use $selected to retrieve all the related pods content with:

$pods= new Pod('my-pod-type');
$params['select'] = '*';
$params['orderby'] = 't.name';
$params['limit'] = 25;
$params['where'] = 'category.name LIKE "'.$selected.'"';