1. Home
  2. Docs
  3. Simpods MVC
  4. Basic Components
  5. Hierarchy

Hierarchy

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:

  • Reduce the burden of WordPress tables (termeta, terms, term_relationships, term_taxonomy) for relationship, especially when you don’t need to create pages for categories.
  • Strictly one to many structure, so you can trace the parent, grandparent categories easily.

  • Custom SQL query is easier as you don’t have to write a lot of join commands to fetch a category title. If you cannot be bothered to write your own SQL query, the simpods_select_fn() will do the job for you.

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:

  • Child Table: list the Pods table you have created.

  • Parent Table: list the Pods table you have created except the one you pick for Child Table.

  • Grandparent Item: If you have created a hierarchy item for the Parent Table, you will be able to pick Grandparent Item. You can leave it to All, or pick a grandparent item which will only list all parent items assigned to it. If you create one with All and another one with a grandparent item, the second one will be ignored as All has higher priority.

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).

Add New - Simpods

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).

Add New Post Type - Simpods

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.

Hierarchy - Simpods

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.

Module Pages hierarchy filter - Simpods

Figure 6. Simpods Hierarchy filter

Coding

If you are using simpods_select_fn(),  in your code, do the following to pull out data with its category. In our example above, the Pods table is pods_module-page:

Copy to Clipboard

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:

Copy to Clipboard

To update the hierarchy of an item, use the code below. You will have to populate the $atts_arr array.

Copy to Clipboard