Add tag-like functionality to your pod inputs

Yet another update: The code below expects the name of your pick field to correspond to the name of the related pod type ( i.e. a pickfield name “genre” should relate to a pod called “genre” , as opposed to “file_type”).

Warning: My code highlighter is gimping up the code a little. If you plan to copy/paste, please download the text file instead of copying straight from the webpag.

Try the DEMO
(login using guest/guest).

Update: The demo was down yesterday because I was playing with some code. Sorry about that.

Update 2:
Also note that if this input helper isn’t working on your site make sure that you’ve enqueued the “suggest” script which ships automatically with WordPress. Do this by adding the following line of code to your functions.php file:

if (!wp_script_is('suggest', 'queue') && !wp_script_is('suggest', 'to_do') && !wp_script_is('suggest', 'done'))  {

So this isn’t really a helper so I’m not going to add it to the PodsCMS helper gallery. However, I think it’s a useful bit of code for pods developers.

The problem: You prefer using pods for developing content that needs lots of relationships managed seamlessly. Post types and tags just won’t cut it. But man, you miss that slick tag UI that WordPress has where you just start typing, hit enter and POW the tag is added. Pods doesn’t have anything like this natively.

The solution:

First create a new input helper and paste in the following code:


This helper creates an input field and calls up some jQuery magic to make it auto-complete. But in order for this magic to work you need to add a function to your functions.php (or a plugin file if that’s the case) and hook it to the wp_ajax_{$action} hook. For more about this hook check Gary Cao’s article.

function ajax_pod_search() {
if(isset($_GET['q'])) {
$str = $_GET['q'];
if(strlen($str) < 2) { die; }
$pod = $_GET['datatype'];
global $wpdb;
$query = $wpdb->prepare("SELECT name FROM {$wpdb->prefix}pod_tbl_{$pod} WHERE name LIKE '%s'", '%'.like_escape($str).'%'); 
$results = $wpdb->get_col($query);
echo join( $results, "n" );

Now simply deploy the input_helper on your chosen multi-pick field pod.

But wait! It’s not saving your pod items. That’s because PodsCMS expects to receive a list of comma-separated pod ids to register the relationship. But our jQuery is outputting the name instead.

So we now need to add a pre-save helper to manage migrating tag names to ids.

save_pod_item(array('datatype'=>$field, 'columns' => array('name'=>$name)));
} else {
$pid = (is_array($pid)) ? $pid[0] : $pid;
$vals[] = $pid; 
} else {
$pid = pod_check($field, $name, 'name'); 
  $new_tag = new PodAPI();
  $pid = $new_tag->save_pod_item(array('datatype'=>$field, 'columns' => array('name'=>$name)));
} else {
$pid = (is_array($pid)) ? $pid[0] : $pid;
$vals = $pid; 
$val_str = implode(',',$vals);
$columns[$field]['value'] = $val_str;

Note that we have to tell the helper the field to which we want it to apply. We do this by setting the $field variable. If you are going to use the input helper on multiple fields, you’ll want to create a pre-save helper for each field. This helper will iterate over the submitted pod names, check to see if that pod exists already and getting its id. If the pod name does not already exist, the helper will create it.

Note that this helper makes use of a function called “pod_check”. You will need to add this function to your functions.php file as well.

function pod_check($datatype, $value='', $field='id') {
    global $wpdb;
    $datatype = pods_sanitize($datatype);
    $field = pods_sanitize($field);
    $return = $wpdb->get_col($wpdb->prepare("SELECT `id` FROM `{$wpdb->prefix}pod_tbl_{$datatype}` WHERE `$field` = ".('id'==$field?"%d":"%s"),array($value)));
    if (true == $return && 0 < $return) {
    return $return;
    } else {
    return false;

This function actually does the work of looking up the pod id.

And that's it. You can make any pod into a "tag" using this approach. But keep in mind that if you are using this field to relate a pods with required fields, you will need to modify the pre-save helper to add those required fields.

WordPress PodsCMS Widgets

I’m not sure why it took me this long to put this plugin together, but whatever. I’ve been using WordPress PodCMS plugin for a long time now. And quite often I need to add pod stuff to a sidebar. Usually, I’d go find a custom sidebar that I’d made before and adapt it. But then I realized how super easy it would be to have a widget that allows you to select which Pod you want to show and which template you want to show it with !!! so bang!

WordPress PodsCMS Widgets – Version 0.1

WordPress PodsCMS SEO Titles Plugin

I haven’t submit this plugin to the WordPress SVN yet, because I’m still playing with it. The remaining issue is that while it works, I’m not sure it works in the most efficient manner possible. I’m also going to post it over at @podscms and get some feedback.

At any rate, for anyone who’s running a pods installation and having trouble getting SEO friendly titles on your pod pages, this plugin creates a template tag <?php pods_seo_title(); ?> that you can use to override wordpress default behavior. The plugins check to see if the page is a pod page, and if so calls the title of the respective pod. If not, it checks to see if the page is singular and returns the TITLE | SITENAME format if it is. Otherwise it returns the SITENAME | SITE DESCRIPTION form.

Download: Pods SEO Titles

WordPress CMS has arrived

header-logoI work for a non-profit and most of my freelance clients are non-profits. Money is scarce but needs are many. Most organizations need a full content management system. They need an events calendar, a multimedia gallery, a press release section and a dozen other content types. But they can’t afford it.

I used to handle this with a mishmash of plugins for calendars, downloads, videos, etc. But the problem was each solution was discrete. For instance, it was difficult to associate a video with an event. This is because, for all its advantages, the WordPress core simply is not a CMS. It basically has two content types: post and page. Yes, the functionality of custom fields helps boost the performance of these two types. But custom fields are cumbersome and user un-friendly.

What WordPress needed was some sort of content construction plugin that would allows users to create their own types of content beyond the post and page.

A few months ago, I discovered a new plugin that does just that. It’s called Pods. Pods is a very efficient framework that sits on top of your WordPress installation. It allows you to easily create content types and then theme those types.

Over the next couple weeks I’m going to post a series of tutorials on different ways you can use pods. In the meantime, head over to their site and download the plugin.