A bit of pods bulk actions history

One of my previous visitors asked for examples showing the usage of bulk actions. The lack of this functionality was one of the main issues of pods in version 1.x. Many of my clients were asking me for a solution to better manage hundreds (or even thousands) of records they had in their DBs. Now we have bulk actions bundled with version 2.2 and we can use it to enhance our UI for better user experience.

Sidenote: have you seen my pods framework code examples on github? 

Let’s move on

Enough history – lets move to “here and now” and start the coding. In one of my previous tutorials about pods framework UI I have shown you how to build a simple UI plugin to manage authors and their books. Today I would like extend this plugin to give user a possibility to use bulk actions.

We can use the package from the previous tutorial so please download it here if you don’t have it yet.  After you download it, please perform one change in our data structure –  remove “required” parameter from the stock field in books pod. Otherwise if we provide 0(zero)  then we will receive a validation error and our bulk action will fail.

Let’s start with something really, really simple. At the moment we are still on pods 2.2 version (2.3 is coming soon) and the plugin comes with one default bulk action – delete. In order to enable this function you simply need to pass an array to your pods UI parameters like this:

This short snippet is all that you need to enable built-in delete action. But what should we do if we want to add our own function?

First we need to know what our function should do. The easiest example which came to my mind was to clear book stocks to 0 (zero). That should be a good example of how to add bulk action support to your plugin.

First of all we need to add another array to bulk actions parameter specifying:

  • the label used in bulk actions dropdown,
  • name of our function which we want to call for each selected item.

Next thing is to build our function. Unfortunately – as in previous tutorials I will not dissect the code and explain it line by line. Of course everything will be commented as always.

Few things to remember:

  • our function takes pods $obj as parameter,
  • $obj->bulk contains all IDs selected by user
  • after successful action we need to redirect our user back to manage screen and display him a message,
  • pods_redirect redirects us back to our action_bulk callback function so we can finish our process and display final message.


Related posts

Posted by Kamil Grzegorczyk Owner / Development

  • chrisspicuzza

    This example is awesome! I used it to setup Approve/Unapprove bulk actions. I do have one issue though. Often it will display the success message but the fields don’t save. I have to run the bulk action once again then it goes. Any ideas? I pretty much used your example.

    • Kamil Grzegorczyk

      well I would need to see more details. Debugging sometimes is the most difficult part of the process 😉

      • chrisspicuzza

        I was about to get to that.. haha. I would you like to go about it? Pastebin? Pods package export? I appreciate your interest in the matter!

        • Kamil Grzegorczyk

          Well I wouldn’t have too much time to play with the package export and installing all of the things so pastebin will be better.

  • chrisspicuzza

    http://pastebin.com/dErRisUg woops… forgot to make it a reply

    • Kamil Grzegorczyk

      I went through it line by line but at a first glance everything seems okay.

      My tutorial was based on early verson of 2.3 so maybe there are slight differences in plugin implementation at the moment or in your environment.

      Please try doing it ona fresh installation with my example and move it from there.

  • Praj

    First of all, i’d like to say I’m a noob when it comes to PHP. I’m mainly a HTML Frontend developer. I’m trying to use Pods in a custom theme i purchased, So far I’ve created my own content type, did not enable ACT. i want to be able to query the Content type, just like Post. So i can list the Recent entries. Any suggestion?

    • Kamil Grzegorczyk


      Unfortunately in order to use PODS efficiently you have to be at least advanced in PHP.

Like what you see?

Contact us today and get started!