Skip Navigation

[Resolved] list child posts in a table, using taxonomy filter

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by Christian Cox 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1313667
Medicinal-Complaints-Screen.JPG

Hi
Attached screenshot shows the result I want. I previously achieved this using Types custom fields but would prefer to use taxonomies. In the screenshot System, Complaint, Actions and Parts Used are all taxonomies. The view is filtered and sorted by System, the System should only appear with the first complaint - as in Gastrointestinal in the screenshot.
Please could you explain the steps needed to achieve this using a taxonomy filter.
Thanks for any help
David

#1313927

Hi, let me make sure I understand what I'm looking at here.

- It looks like "Source" is a child post of "Plant", is that correct? If not, can you tell me more about how each row in the table is created? For example the first row - how is "Endocrine/Metabolism" related to "diabetes" and "hypoglycemic" and "root" if they are terms in separate taxonomies?

- Is the table sortable or filterable on the front-end of the site, or is sorting and filtering predefined?

- How is Preparation and Administration defined?

#1313933

Hi Christian, Good to hear from you.
Yes all fields in the screenshot belong to the medicinal complaint custom post which is a child post of the plant that's used to treat the complaint, the View of the posts shown in the screenshot are included in the content template that displays plant post details as

[wpv-view name="complaints-list-new-table"]

The fields of the medicinal complaint post are:
Name -------------- Type
Source ------------ Taxonomy
Complaint --------Taxonomy
Actions ----------- Taxonomy
Prep & Admin - Custom Field
Parts Used ----- Taxonomy
Source ---------- Custom Field
There's also the Title field that does not appear 'cause it includes an id no. to avoid duplicate post titles. The post also includes complaint id and parent plant id that I upload and are not connected to the post id numbers.
Hope this makes it a bit clearer.
Thanks for your help
David

#1314581

Okay thanks. Natively, WordPress does not support ordering a post query by taxonomy in WP_Query: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

Views uses WP_Query, so this is the first challenge you'll have to overcome. We offer the API wpv_filter_query_post_process, which will allow you to reorder the results in a View based on your own custom code after the query has already been run. This works best with non-paginated Views. This API will also allow you to programmatically remove the "System" taxonomy name for all except the first of its type. But again, this is fairly custom PHP code. There are some examples here and in the forums:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

One built-in alternative is to use a sortable Table View. This will give your Users the ability to sort the table by column header (for most simple field types). This won't achieve the goal of hiding the System term in all but the first instance, so that would require some other custom code.

Let me know if you have questions about the Toolset API and I can provide more guidance.

#1314637

Hi Christian,
Thanks for this.
For the purposes of this table View what data type would be best - simplest for me - to use for the System field - every medicinal complaint post has one System - there are a total of 14 Systems.
Are there any examples of Views using wpv_filter_query_post_process or the sortable Table View ?

Thanks
David

#1314647

It's a matter of personal preference, to some degree. I like flat taxonomies for this case because they are implemented with an auto-suggest text field. I prefer typing to clicking, so that works better for me, but you might prefer another input type. Also there's nothing to prevent you or another admin from adding more than one term to a Complaint post, accidentally. A custom radio field or custom select field would prevent that, but then you wouldn't get the added benefit of a custom taxonomy archive for each term. So there are pros and cons to consider for each type.

#1314723

Hi Christian,
Is there an example of a sortable Table View using a taxonomy filter that you could point me to?
Thanks
David

#1314815

I just tried to set this up to share with you, and realized that I gave you inaccurate information. Even a sortable table View will not be sorted correctly by taxonomy term. The system will let you add the taxonomy as a column in the table, but sorting just defaults back to the post date. So it turns out sorting by term isn't going to be achieved simply in wp-admin, it's going to require custom code because of limitations in the WordPress query engine.

#1314851

Good I asked before starting on the table view.
If I store fields that I want to show sorted in a table and also allow users to search by these fields, could I duplicate these fields storing as a taxonomy and also as a custom field, any disadvantages in doing this?
Seems a simple solution to take advantage of auto complete search and sortable table view.
Thanks
David

#1314973

If I store fields that I want to show sorted in a table and also allow users to search by these fields, could I duplicate these fields storing as a taxonomy and also as a custom field, any disadvantages in doing this?
Database size would be something to consider, as well as duplicate work in management of the terms and fields in wp-admin and in Forms. To some degree you might be able to automate this with custom code.

#1315063

Thanks for this,
I don't think database size should be an issue, and the database is static, that is once the info's loaded it will not change so I don't see any extra work managing terms and fields.
I think I'm going to go with this solution, appreciate if you could point me to a table view example
Thanks
David

#1315545

Sure, here are a couple of basic Views documents that include information about table displays:
https://toolset.com/documentation/getting-started-with-toolset/create-and-display-custom-lists-of-content/
https://toolset.com/documentation/user-guides/view-layouts-101/

Let me know if you need something more specific.