Simpods Hierarchy has been created to take advantage of Pods Framework’s tables. The idea behind it is that you can use items from a Pods table as another Pods table’s categories. The benefits are:
Figure 1. Hierarchy
Dependencies
The Simpods Hierarchy functionality requires the Pods Framework plugin to be installed, along with the “Advanced Content Type” and “Table Storage” components
How to use it?
There are three fields to set:
Let’s learn it from an example. It is actually the way we set up our CPD course structure. In our CPD things are divided into three levels: Course, Module and Module Pages. You create a course, and then create modules to assign to the course. After that, you create module pages to assign to each module. They are strictly one to many structure. Now we go to Pods Admin – Add New to create three new pods: course, module and module-page (Figure 2).
Figure 2. Add New Pod
We will pick Custom Post Type and Table Based storage, as we need to create pages for them (Figure 3).
Figure 3. Create New Pod
After you have created the pods, go back Simpods Hierarchy, set the fields and save them, you will see a table like the one in Figure 4.
Figure 4. Create Simpods Hierarchy items
Now if you go to the modules and module pages, you can find a Hierarchy box on the right to assign your posts to (Figure 5).
Figure 5. Simpods Hierarchy boxes
A filter will also appear on the posts list (Figure 6) to filter posts by the parent category.
Figure 6. Simpods Hierarchy filter
Coding
If you are using simpods_select()
, in your code, do the following to pull out data with its category. In our example above, the Pods table is pods_module-page:
Do the following to pull out data in a category. Replace {module Pod ID}
with a real Pod ID and {module item ID}
with a real module item ID:
To update the hierarchy of an item, use the code below. You will have to populate the $atts_arr
array.